As a reminder, the Math class often appears when reading code in programming. .. .. ** It is written as an excerpt. It is not exhaustive. ** **
E
The double value closest to the base of the natural logarithm (Napier, Euler) ʻeis2.718281828459045`.
PI
The double value closest to pi π is 3.141592653589793.
abs
| argument | Return value |
|---|---|
| double | double |
| float | float |
| int | int |
| long | long |
A method to find the absolute value.
Math.abs (-5) is 5.
max
| 1st argument | Second argument | Return value |
|---|---|---|
| double | double | double |
| float | float | float |
| int | int | int |
| long | long | long |
Returns the larger of the two numbers set in the argument.
Math.max (2, 7) is 7.
min
| 1st argument | Second argument | Return value |
|---|---|---|
| double | double | double |
| float | float | float |
| int | int | int |
| long | long | long |
The opposite of max, it returns the smaller of the two numbers set in the argument.
Math.max (10, 4) is 4.
pow
| 1st argument | Second argument | Return value |
|---|---|---|
| double | double | double |
Find the power.
Math.pow (a, b) returns ʻa ^ b. That is, Math.pow (3.0, 4.0)is81.0`.
sqrt
| argument | Return value |
|---|---|
| double | double |
Find the rounded positive square root.
In short, it's a root guy.
If the argument is ʻa, the number xsuch thatx ^ 2 = ais obtained. Math.sqrt (9.0)is3.0. It's 3 ^ 2 = 9`!
cbrt
| argument | Return value |
|---|---|
| double | double |
It seeks a cube root.
If the argument is ʻa, the number xsuch thatx ^ 3 = ais obtained. Math.cbrt (8.0)is2.0. It's 2 ^ 3 = 8`!
ceil
| argument | Return value |
|---|---|
| double | double |
Round up the argument.
Strictly speaking, it returns "the number greater than or equal to the argument and equal to the calculated integer, closest to negative infinity".
Math.ceil (1.34) is 2.0.
Math.ceil (-3.89) is -3.0.
floor
| argument | Return value |
|---|---|
| double | double |
Truncate the argument.
Strictly speaking, it returns "the number less than or equal to the argument and equal to the calculated integer, closest to positive infinity".
Math.floor (1.34) is 1.0.
Math.floor (-3.89) is -4.0.
round
| argument | Return value |
|---|---|
| double | long |
| float | int |
Returns the number rounded off.
In fact, it does some bitwise operations internally, but it's ** rounded **!
Math.round (1.34) is 1.
Math.round (-3.89) is -4.
rint
| argument | Return value |
|---|---|
| double | double |
Returns the number rounded off.
The only difference from round is the argument and return types.
toRadians
| argument | Return value |
|---|---|
| double | double |
Converts arguments expressed in degrees (units: °, degrees) to arcs (units: radians).
Radian=Every time* π / 180
toDegrees
| argument | Return value |
|---|---|
| double | double |
The opposite of toRadians, it converts the arguments represented by the arc degree method to the frequency method.
to Radians.
By the way, you can also convert with the following formula.Every time=Radian* 180 / π
sin
| argument | Return value |
|---|---|
| double | double |
Returns the sine (sine) of the specified angle.
The argument must be expressed in radians.
That is, sin30 ° is represented byMath.sin (Math.toRadians (30.0)).
However, at least in my environment, when I run Math.sin (Math.toRadians (30.0)), I get 0.49999999999999994, so I think that proper rounding is necessary.
cos
| argument | Return value |
|---|---|
| double | double |
Returns the cosine of the specified angle.
The argument must be expressed in radians.
That is, cos60 ° is represented byMath.cos (Math.toRadians (60.0)).
This also returned 0.5000000000000001. Let's roll it up.
tan
| argument | Return value |
|---|---|
| double | double |
Returns the tangent of the specified angle.
The argument must be expressed in radians.
That is, tan 45 ° is represented byMath.tan (Math.toRadians (45.0)).
This also returned 0.99999999999999999.
asin
| argument | Return value |
|---|---|
| double | double |
Returns the inverse sine (arc sine) of the specified value.
The range of angles returned is -π / 2 ≤ x ≤ π / 2.
For example, if the argument is ʻa, the size of the angle expressed by the radian method xis obtained so thatsinx = a. Math.asin (0.5)is0.5235987755982989 (≒ π / 6`).
acos
| argument | Return value |
|---|---|
| double | double |
Returns the inverse cosine (arc cosine) of the specified value.
The range of angles returned is 0.0 ≤ x ≤ π.
For example, if the argument is ʻa, the size of the angle expressed by the radian methodxis obtained so thatcosx = a. Math.acos (0.5)is1.0471975511965979 (≒ π / 3`).
atan
| argument | Return value |
|---|---|
| double | double |
Returns the arctangent of the specified value.
The range of angles returned is -π / 2 ≤ x ≤ π / 2.
For example, if the argument is ʻa, the size of the angle expressed by the radian method xis obtained so thattanx = a. Math.atan (1.0)is0.7853981633974483 (≒ π / 4`).
atan2
| 1st argument | Second argument | Return value |
|---|---|---|
| double | double | double |
Returns the angle when converted from Cartesian coordinates to polar coordinates.
The first argument is the y coordinate and the second argument is the x coordinate. (** Note the order **)
In other words, "the angle between the" line segment connecting the origin and the point (x, y) "and the" positive part of the x-axis "in Cartesian coordinates" is returned by the radian method.
Math.atan2 (Math.sqrt (3.0), 1.0) is 1.0471975511965976 (≒ π / 3).
random
| argument | Return value |
|---|---|
| --- | double |
Returns a random positive value greater than or equal to 0.0 and less than 1.0.
Exactly the same as java.util.Random ().
addExtract
| 1st argument | Second argument | Return value |
|---|---|---|
| int | int | int |
| long | long | long |
Returns the sum of the arguments.
Throws an exception if the result overflows an int or long.
Math.addExact (1, 5) is 6.
subtractExtract
| 1st argument | Second argument | Return value |
|---|---|---|
| int | int | int |
| long | long | long |
Returns the difference between the arguments.
Throws an exception if the result overflows an int or long.
Math.subtractExact (1, 5) is -4.
multiplyExact
| 1st argument | Second argument | Return value |
|---|---|---|
| int | int | int |
| long | long | long |
Returns the product of the arguments.
Throws an exception if the result overflows an int or long.
Math.multiplyExact (2, 5) is 10.
incrementExact
| argument | Return value |
|---|---|
| int | int |
| long | long |
Returns the argument incremented by 1.
Throws an exception if the result overflows an int or long.
If the argument is ʻa, the process is almost the same as ʻa ++.
decrementExact
| argument | Return value |
|---|---|
| int | int |
| long | long |
Returns the argument decremented by 1.
Throws an exception if the result overflows an int or long.
If the argument is ʻa, the process is almost the same as ʻa--.
negateExact
| argument | Return value |
|---|---|
| int | int |
| long | long |
Returns the negation of the argument. Throws an exception if the result overflows an int or long.
If the argument is ʻa, it is almost the same as the process that -a is returned, but if you put ʻInteger.MIN_VALUE in the argument, an exception will occur. (Because int type is -2147483648 ~ 2147483647)
toIntExact
| argument | Return value |
|---|---|
| long | int |
Returns a long argument as an int. Throws an exception if the value does not fit in an int.
floorDiv
| 1st argument | Second argument | Return value |
|---|---|---|
| int | int | int |
| long | long | long |
Returns the maximum (closest to positive infinity) value less than or equal to the quotient algebra.
Math.floorDiv (a, b) returns " floor of the quotient of ʻa divided by b". For example,-5 ÷ 3 is -1.6666 ... , so Math.floorDiv (-5, 3) is -2`.
floorMod
| 1st argument | Second argument | Return value |
|---|---|---|
| int | int | int |
| long | long | long |
Returns the floor modulus of the argument.
Math.floorMod (a, b) returns "too much when ʻa is divided by band its quotient isfloorDiv (a, b)". For example, Math.floorDiv (-5, 3)is-2, so Math.floorMod (-5, 3) is 1`.
In other words, the following formula holds.
b = Math.floorDiv(a, b) * b + Math.floorMod(a, b)
exp
| argument | Return value |
|---|---|
| double | double |
Returns the number of Napiers (Euler numbers) ʻe raised to the power of a double value. If the argument is ʻa, ʻe ^ a` is returned.
signum
| argument | Return value |
|---|---|
| double | double |
| float | float |
If the argument is a,
When ʻa <0, -1.0, When ʻa = 0, 0.0,
Returns 1.0 when ʻa> 0`.
hypot
| 1st argument | Second argument | Return value |
|---|---|---|
| double | double | double |
Returns sqrt (x ^ 2 + y ^ 2).
No overflow or underflow will occur along the way.
That is, Math.hypot (x, y) returns the "distance from the origin to the point (x, y) on the coordinate plane".
log
| argument | Return value |
|---|---|
| double | double |
Returns the natural logarithmic value of the argument (base e).
That is, if the argument is ʻa, it returns the value x such that ʻe ^ x = a.
log10
| argument | Return value |
|---|---|
| double | double |
Returns the common logarithmic value of the argument.
That is, if the argument is ʻa, it returns the value xsuch that10 ^ x = a. Math.log10 (1000.0)is3.0`.
** IMIWAKARAN **
Recommended Posts