Wednesday 29 May 2013

java.lang.Math FUNCTIONS - A SHORT DESCRIPTION OF MOST OF THE MATHEMATICAL FUNCTIONS IN JAVA

Here are most of the methods that that are included in the Math class of java.lang package. I have mentioned most of the methods with prototype, description related to returning value of the method, and some examples for each method along with their output.



1-17 are the Rounding functions
18-21 are Exponential functions
22-28 are the Transcendental functions
29-32 are some Miscellaneous math functions.

S.NO.
METHOD PROTOTYPE
DESCRIPTION
EXAMPLE
OUTPUT
1.
static int abs(int arg)
Returns absolute value of arg
System.out.println(Math.abs(-5));
5
2.
static long abs(long arg)
Returns absolute value of arg
System.out.println(Math.abs(-256));
256
3.
Static float abs(float arg)
Returns absolute value of arg
System.out.println(Math.abs(-5.36f));
5.36
4.
static double abs(double arg)
Returns absolute value of arg
System.out.println(Math.abs(-5.31555));
5.3155





5.
static double ceil(double arg)
Returns the smallest integer greater than or equal to arg
System.out.println(Math.ceil(7.5));
8



System.out.println(Math.ceil(-7.8));
-7





6.
static double floor(double arg)
Returns the greatest integer less than or equal to arg
System.out.println(Math.floor(7.5));
7



System.out.println(Math.floor(-7.5));
-8





7.
static int max(int x,int y)
Returns the maximum of x and y
System.out.println(Math.max(3,5));
5
8.
Static long max(long x,long y)
Returns the maximum of x and y
System.out.println(Math.max(312546,598545));
598545
9.
static float max(float x,float y)
Returns the maximum of x and y
System.out.println(Math.max(3.2,5.6));
5.6
10.
static double max(double x,double y)
Returns the maximum of x and y
System.out.println(Math.max(3.1254,3.2145));
3.2145





11.
static int min(int x,int y)
Returns the minimum  of x and y
System.out.println(Math.min (3,5));
3
12.
Static long min(long x,long y)
Returns the minimum of x and y
System.out.println(Math.min (312546,598545));
312546
13.
static float min(float x,float y)
Returns the minimum of x and y
System.out.println(Math.min (3.2,5.6));
3.2
14.
static double min(double x,double y)
Returns the minimum of x and y
System.out.println(Math.min (3.1254,3.2145));
3.1254





15.
static double rint(double arg)
Returns an integer nearest to arg
System.out.println(Math.rint(2.3));
2



System.out.println(Math.rint(2.5));
2



System.out.println(Math.rint(2.8));
3



System.out.println(Math.rint(2.500001));
3





16.
static int round(float arg)
Return arg rounded up to nearest integer
System.out.println(Math.round(2.2));
2



System.out.println(Math.round(2.8));
3



System.out.println(Math.round(2.5));
3



System.out.println(Math.round(2.4999));
2





17.
static long round(double arg)
Return arg rounded up to nearest integer
System.out.println(Math.round(2.2));
2



System.out.println(Math.round(2.8));
3



System.out.println(Math.round(2.5));
3



System.out.println(Math.round(2.4999));
2





18.
static double exp(double arg)
Returns e to the power arg
System.out.println(Math.exp(5.3));
200.33680997479166





19.
static double log(double arg)
Returns the natural logarithm of arg
System.out.println(Math.log (5.3));
1.667706820558076





20.
static double pow(double x,double y)
Returns y raised to the power
System.out.println(Math.pow (5.3,2.3));
46.327034412240806






21.
static double sqrt(double arg)
Returns the square root of arg
System.out.println(Math.sqrt (5.3));
2.3021728866442674





22.
static double sin(double arg)
Returns the sine of angle (in radians) specified by arg
System.out.println(Math.sin (2.3));
0.7457052121767203





23.
static double cos(double arg)
Returns the cosine of angle (in radians) specified by arg
System.out.println(Math.cos (2.3));
-0.666276021279824





24.
static double tan(double arg)
Returns the tangent of angle (in radians) specified by arg
System.out.println(Math.tan (2.3));
-1.1192136417341325





25.
static double asin(double arg)
Returns the angle in radian whose sine is specified by agr
System.out.println(Math.asin (0.3));
0.3046926540153975



System.out.println(Math.asin (2.3));
NaN





26.
static double acos(double arg)
Returns the angle in radian whose cosine is specified by agr
System.out.println(Math.acos (0.3));
1.2661036727794992



System.out.println(Math.acos (2.3));
NaN





27.
static double atan(double arg)
Returns the angle in radian whose tangent is specified by agr
System.out.println(Math.atan (0.3));
0.2914567944778671





28.
static double atan2(double arg1,double arg2)
Returns the angle in radian whose tangent is arg1/arg2
System.out.println(Math.atan2 (5.3,2.3));
1.1613591172687538





29.
static double toRadians(double arg)
Returns angle in radians that was specified in degrees by user
System.out.println(Math.toRadians (60));
1.0471975511965976





30.
static double toDegrees(double arg)
Returns angle in degrees that was specified in radians by user
System.out.println(Math.toDegrees(1.325));
75.91690785483408





31.
static double random()
Returns a random number between 0 and 1
System.out.println(Math.random());
0.6442722773831705





32.
Static double IEEEremainder(double a,double b)
Returns  a-b*Math.rint((double)a/(double)b)
System.out.println(86,8)
-2.0



System.out.println(86.54,8)
-1.4599999999999937



System.out.println(90.54,8)
2.5400000000000063

No comments:

Post a Comment