Home » Java » Mathematical calculation function in Java

Mathematical calculation function in Java

Math class:
The java.lang.Math class contains basic numeric operations such as indices, logarithms, square roots and trigonometric functions.

Java.math is a package that provides classes for executing arbitrary precision integer (BigInteger) algorithms and arbitrary precision decimal (BigDecimal) algorithms (.
)


The java.lang.Math class contains two static constants, E and PI, and a class (static) method for scientific computing that calls.
directly through the class name
Public, static, final, Double, E = 2.7182818284590452354

Public, static, final, Double, PI = 3.14159265358979323846



Public static long ABS (double x): returns the absolute value of.X, x, also int, long, float

Public, static, long, sin (double, x): the value of the sine function that returns the X diameter

Public, static, long, cos (double, x): the cosine function value that returns the X diameter

Public, static, long, Tan (double, x): the tangent function value that returns the X diameter

Public static long asin (double x): returns the value of the inverse sine function.
of the x value
Public static long ACOS (double x): returns the value of the inverse cosine function.
of the x value
Public static long atan (double x): returns the value of the tangent function.
of the x value
Public static long atan2 (double, x, double, y): returns the theta value of the polar coordinate (polar)

Public static long floor (double x): returns the maximum integer value of not greater than x

Public static long ceil (double x): returns a minimum integer value of not less than x.

Public static long exp (double x): returns equivalent to the ex value

Public static long log (double x): returns the natural logarithm function value of X

Public, static, long, max (double, x, double, y): returns x, y, larger number

Public, static, long, min (double, x, double, y): returns x, y is smaller than

Public, static, long, pow (double, x, double, y): returns the Y power value
of X
Public static long sqrt (double x): returns the x square value

Public static long rint (double x): returns the integer value x closest to

Public static long round (double x): returns four to five of the value of X,

Public static long toDegrees (double angrad): returns the angrad diameter to angle

Public static long toRadians (double angdeg): returns the angdeg angle to diameter

Public static long random (): returns a random value that produces a random number between 0-1 (excluding 0 and 1)



NumberFormat class:
(public, abstract, class, NumberFormat, extends, Format)

Use the java.text.NumberFormat class to format the output numeric results.





Instantiate a NumberFormat object with the following method class:

Public, static, final, NumberFormat, getInstance ()

Then call the following method with this object, you can format the number number (return string object):

Public, final, String, format (double, number)



The NumberFormat class has the following common methods:

Public void setMaximumFractionDigits (int newValue) / / maximum number of.
is allowed to set the number of the fractional part
Public void setMaximumIntegerDigits (int newValue) / / maximum number of.
allowed the integer part of the number set
Public void setMinimumFractionDigits (int newValue) / /.
permitted minimum number of decimal number of the set
Public void setMinimumIntegerDigits (int newValue) / minimum number of.
permitted the integer part of the number of set
(for more methods and usage, see the JDK6API reference.)





The BigInteger class, the BigDecimal class:
The BigInteger class and the BigDecimal class in the java.math package provide arbitrary precision integer and decimal operations, respectively..

Like the two class design ideas, here is a brief introduction to the BigInterger class. For details, you can see the JDK6API reference.



The construction method is as follows:

BigInteger (String VAL) / / decimal string representation of the BigInteger converted to BigInteger.

There are many well thought out constructors, and it is recommended that you write down the JDK.
before you write the BigInteger for a particular requirement


Common method:

(ABS) / / return its value is the BigInteger of the absolute value of BigInteger.

Add (BigInteger VAL) / / return the value of (this+val) BigInteger.

Subtract (BigInteger VAL) / / return the value of (this-val) BigInteger.

Multiply (BigInteger VAL) / / return the value of (this*val) BigInteger.

Divide (BigInteger VAL) / / return the value of (this/val) BigInteger.

Remainder (BigInteger VAL) / / return the value of (this%val) BigInteger.

CompareTo (BigInteger VAL) / / this BigInteger with the specified BigInteger were compared. The return value of 1,0, -1 are greater than, equal to, less than

Pow (int exponent) / / returns the current large number of power of exponent.

(toString) / / returns the decimal string representation of the BigInteger.

toString (int radix) / BigInteger (given cardinality returns this Radix hexadecimal string representation of the.

)
Supplement:
(1) ABS (): returns the absolute value of a number. The arguments can be float, double, long, or int.. If they are byte or short types, they are coerced into int type.

(2) (ceil) will find the largest integer next. Parameters such as 9.01, 10.0. returned to -0.1, returns -0.0. returns the integer ratio parameter is large, and double precision type. If the parameter is an integer, double precision.
the method returns the parameters
(3) floor () returns the nearest integer. The function is the reverse of ceil (), returning an integer smaller than the parameter, and both of them are double precision. If the parameter is integer, the double precision.
of this parameter is returned
(4) max () returns the maximum value in the two value; supports only float double long int, and does not support byte short.

(5) min () returns the minimum value in the two value; supports only float double long int, and does not support byte short.

(6) random () returns a random number, a double precision number.
between 0 and 1
(7) (round) returned to the nearest integer and a floating-point value. This parameter can be double and folat two, and four to five homes. For example: the parameters of 9.01, return 9, 9.5 parameters, 10 parameters for the return, -9.5, or -9.

(8) sqrt () returns the square root of a value. If the parameter is a non numeric type (NaN), or less than zero, then the return is NaN.

Latest