0% found this document useful (0 votes)
126 views30 pages

Mthematical Library Methods

The document discusses various mathematical library functions in Java's Math class. It describes functions like min(), max(), pow(), sqrt(), abs(), log(), round(), rint(), ceil(), floor(), exp(), trigonometric functions, and random(). These functions allow performing common mathematical operations easily in Java programs. The angles for trigonometric functions need to be passed in radians. Degrees can be converted to radians using appropriate formulas.

Uploaded by

Ashwini KS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views30 pages

Mthematical Library Methods

The document discusses various mathematical library functions in Java's Math class. It describes functions like min(), max(), pow(), sqrt(), abs(), log(), round(), rint(), ceil(), floor(), exp(), trigonometric functions, and random(). These functions allow performing common mathematical operations easily in Java programs. The angles for trigonometric functions need to be passed in radians. Degrees can be converted to radians using appropriate formulas.

Uploaded by

Ashwini KS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

1

Lorven Public School, Chandapura


MATHEMATICAL
LIBRARY METHODS
BY ASHWINI K S
INTRODUCTION 2

Lorven Public School, Chandapura


 There are some function designed and developed to help the user to perform
certain tasks easily and quickly.
 Mathematical library functions are some those functions.
 These function are developed to perform some mathematical operation.
 These is class called ‘math’ in which many functions defined.
 This class is in ’java.lang’ package.
 The general syntax of using math function in java program is as follows.
 Math. <method name>
Math. min() 3

Lorven Public School, Chandapura


 It returns the minimum of 2 numbers.
 Return type may be int /long/double , depending on the type of the argument.
 Syntax :
 <return type> <variable>=< function name(arg1, agr2)> ;
 Example :
 Float x = Math.min( 6.3, 2.0)
 Output : 2.0
Math.max() 4

Lorven Public School, Chandapura


 It returns the greatest of 2 numbers.
 Return type may be int /long/double , depending on the type of the argument.
 Syntax :
 <return type> <variable>=< function name(arg1, agr2)> ;
 Example :
 Float x = Math.max( -5.3, -2.7)
 Output : -2.7
Math.pow() 5

Lorven Public School, Chandapura


 This method is used to find the power raised to given base number
 It returns the double value
 Syntax :
 <return type> <variable>=< function name(arg1, agr2)> ;
 Example :
 double x = Math.pow( 3, 3) =33
 Output : 27
Math.sqrt() 6

Lorven Public School, Chandapura


 This method is used to find the square root raised of a positive number
 It returns the double value
 Syntax :
 <return type> <variable>=< function name(positive number)> ;
 Example :
 doublet x = Math.sqrt(4)
 Output : 2
Math.cbrt() 7

Lorven Public School, Chandapura


 This method is used to find the cube root of a positive number
 It returns the double value
 Syntax :
 <return type> <variable>=< function name(positive number)> ;
 Example :
 double x = Math.cbrt(25)
 Output : 5
Math.abs() 8

Lorven Public School, Chandapura


 This method is used to find the absolute value(magnitude of the number) of the
number given.
 It may return int/long/double value depending on the input.
 Syntax :
 <return type> <variable>=< function name(number)> ;
 Example :
 double x = Math.abs(-9. 25)
 Output : 9.25
Math.log() 9

Lorven Public School, Chandapura


 http://www.mclph.umn.edu/mathrefresh/logs.html
 https://pdf4pro.com/fullscreen/logarithm-table-for-numbers-1-to-5-7abd0.html
 This method is used to find the natural logarithmic value of a number
 It returns the double value
 Syntax :
 <return type> <variable>=< function name(positive number)> ;
 Example :
 double x = Math.log(6.25)
 Output : 1.8325
Math.round() 10
 This method is used to round up a number to its nearest integer.

Lorven Public School, Chandapura


 If the fractional value is less than 0.5, then it returns same integer.
 If the value is more than 0.5, then it returns next highest integer.
 The round function always rounds the value up, when it’s a middle decimal value
i.e. 0.5 .
 If x= 5.5 then its rounded to 6
 If x= -5.5 then its rounded to -5
 It returns different values for positive and negative numbers.
 It returns the value in long when input value is double
 It returns the value in int when input value is float.
Math.round() 11

Lorven Public School, Chandapura


 Syntax :
 <return type> <variable>=< function name(positive number)> ;
 Example :
 long x = Math.round(6.25)
 Output : 6
 Long x= math.round(-8.5)
 Output.-8
Math.rint() 12

Lorven Public School, Chandapura


 This function returns the nearest integer of a given fractional number.
 The return type double.
 If the argument is positive or negative number, this method will return the nearest
value.
 If two double values that are mathematical integers are equally close, this method
will return integer value that is even.
 If the argument is infinity or positive zero or negative zero, this method will
return the argument value as a result.
Math.rint() 13

Lorven Public School, Chandapura


 Syntax :
 <return type> <variable>=< function name(number)> ;
 Example :
 double x = Math.rint(-9. 5) (negative numbers)
 Output : -10.0
 double x = Math.rint(8. 5) (positive numbers)
 Output : 8
 Test example
Math.ceil() 14

Lorven Public School, Chandapura


 The Math.ceil() function rounds a floating point value up to the nearest integer
value.
 The rounded value is returned as a double.
 Syntax :
 <return type> <variable>=< function name(number)> ;
 Example :
 double ceil = Math.ceil(7.343); // ceil = 8.0
Math.floor() 15

Lorven Public School, Chandapura


 The Math.floor() function rounds a floating point value down to the nearest
integer value.
 The rounded value is returned as a double.
 Syntax :
 <return type> <variable>=< function name(number)> ;
 Example :
 double floor = Math.floor(7.343); // floor = 7.0
Math.exp() 16

Lorven Public School, Chandapura


 The Math.exp() function returns e (Euler's number) raised to the power of the
value provided as parameter.
 Syntax :
 <return type> <variable>=< function name(number)> ;
 Example :
 double exp = Math.exp(2);
 In the example above 2 is the argument. 2 will be the power of the exponential
constant e.
 e = 2.718.
 Output : 7.38905609893065
Trigonometric Math Functions 17

Lorven Public School, Chandapura


 The Java Math class contains a set of trigonometric functions.
 These functions can calculate values used in trigonometry, like sine, cosine, tangent .
 The angles are passed as an argument to the function. The angle has to be passed in
radians.
 Syntax : <return type> <variable>=< function name(angle in radian)> ;
 For example:
 math.sin(x)
 math.cos(x)
 math.tan(x).
Conversion from degree to radian 18

Lorven Public School, Chandapura


 Pi radians are equal to 180 degrees:
 π rad = 180°
 One degree is equal 0.01745329252 radians:
 1° = π/180° = 0.005555556π = 0.01745329252 radian
 radians = degrees × π / 180°
 Example : 30°
 30° × 3.14159 / 180° = 0.5236 rad
Math.random() 19

Lorven Public School, Chandapura


 Math.random() returns a random number between 0 (inclusive), and 1 (exclusive)
 Syntax :
 <return type> <variable>=< function name()> ;
 Example : double d= math.random();
 It will return any random value between 0 and 1 for d.
References 20

Lorven Public School, Chandapura


 https://www.javatpoint.com/java-math
21

Lorven Public School, Chandapura


22

Lorven Public School, Chandapura


23

Lorven Public School, Chandapura


24

Lorven Public School, Chandapura


25

Lorven Public School, Chandapura


26

Lorven Public School, Chandapura


27

Lorven Public School, Chandapura


28

Lorven Public School, Chandapura


29

Lorven Public School, Chandapura


30

Lorven Public School, Chandapura

You might also like