Math class in java

Math class

Help mathematics class Math class is a very useful, very simple to use, this special class, first of all he and the String class are the same as modified by the final, it can not have subclasses, there is its constructor is private, that is, we can not construct new methods in other classes Math object, then how can we call its methods, its original all the methods are static, that is, the class name can be used directly to access the method.

I. Brief Introduction

static double abs(double a)

Returns the absolute value of a double value.

static float abs(float a)

Returns the absolute value of a float.

static int abs(int a)

Returns the absolute value of int.

static long abs(long a)

Returns the absolute value of long value.

static double acos(double a)

Returns the inverse cosine of the angle, in the range of 0.0 to pi.

static double asin(double a)

Returns arcsine angle, in the range of -pi / 2 through pi / 2 between.

static double atan(double a)

Returns the arctangent angle, in the range of -pi / 2 through pi / 2 between.

static double atan2(double y, double x)

Rectangular coordinates (x, y) to polar coordinates (r, theta).

static double cbrt(double a)

Returns the cube root of a double value.

static double ceil(double a)

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument, and equal to an integer.

static double cos(double a)

Returns the trigonometric cosine of an angle.

static double cosh(double x)

Returns the hyperbolic cosine of a double value.

static double exp(double a)

Returns the double value of the power of Euler's number e.

static double expm1(double x)

Back ex -1.

static double floor(double a)

Returns the largest (closest to positive infinity) double value that is less than or equal to the argument, and equal to an integer.

static double hypot(double x, double y)

Returns sqrt (x2 + y2), without intermediate overflow or underflow.

static double IEEEremainder(double f1, double f2)

In accordance with the IEEE 754 standard, two parameters of remainder operation.

static double log(double a)

Back logarithm (base e) the natural logarithm of a double value.

static double log10(double a)

Returns the double value of the base-10 logarithm.

static double log1p(double x)

Parameters and return the natural logarithm and the 1.

static double max(double a, double b)

Two double return values ​​larger one.

static float max(float a, float b)

Two float return values ​​larger one.

static int max(int a, int b)

Int return two values ​​larger one.

static long max(long a, long b)

Two long return values ​​larger one.

static double min(double a, double b)

Two double returns a smaller value.

static float min(float a, float b)

A float returns two values ​​smaller.

static int min(int a, int b)

Int Returns the value of a two smaller.

static long min(long a, long b)

Two long returns a smaller value.

static double pow(double a, double b)

Returns the value of the first parameter of the power of the second parameter.

static double random()

Returns a double value with a positive sign, greater than or equal to 0.0, less than 1.0.

static double rint(double a)

Returns its parameter and is an integer value closest to a double value.

static long round(double a)

Returns the closest long argument.

static int round(float a)

Returns the closest int argument.

static double signum(double d)

Returns the signum function of the argument; If the argument is zero, it returns zero; if the parameter is greater than zero, return 1.0; if the parameter is less than zero, -1.0.

static float signum(float f)

Returns the signum function of the argument; If the argument is zero, it returns zero; if the parameter is greater than zero, return 1.0; if the parameter is less than zero, -1.0.

static double sin(double a)

Returns the trigonometric sine of the angle.

static double sinh(double x)

Returns the hyperbolic sine of a double value.

static double sqrt(double a)

Returns the double value correctly rounded positive square root.

static double tan(double a)

Returns the trigonometric tangent.

static double tanh(double x)

Returns the hyperbolic cosine of a double value.

static double toDegrees(double angrad)

The angle measured in radians converted to approximately equivalent angle measured in degrees.

static double toRadians(double angdeg)

The angle measured in degrees of angle approximately equal to convert measured in radians.

static double ulp(double d)

Returns the size of an ulp parameters.

static float ulp(float f)

Returns the size of an ulp parameters.

Second, the method to use

       System.out.println(Math.PI);
       
       System.out.println(Math.abs(-1));
       
       System.out.println(Math.floor(100.99));
       
       System.out.println(Math.ceil(100.00001));
       
       System.out.println(Math.round(20.4));
       
       System.out.println(Math.max(99, 98));
       
       System.out.println(Math.pow(2, 10));
       
       System.out.println((int)(Math.random()*10));//随机的 1-10
       
       System.out.println(Math.sqrt(9));
       
       System.out.println((-5-Math.sqrt(Math.pow(5, 2)-4*2*2))/2);
       System.out.println("x=");

 

Guess you like

Origin www.cnblogs.com/weibanggang/p/11184677.html