In this article, as part of my output practice, I will note the method of java.lang.Math, which is an API used in mathematical calculations. If there is something wrong with the explanation, it would be helpful if you could point it out. Reference: Official java.lang.Math

abs Find the absolute value of the integer taken as an argument.

```
int num1 = Math.abs(-1); //num1 = 1
```

max, min Returns the larger (smaller) of the two arguments.

```
int num2 = Math.max(1,2); //num2 = 2
int num3 = Math.min(1,2); //num3 = 1
```

random Returns a positively signed double value greater than or equal to 0.0 and less than 1.0. If you want to make it an integer value, multiply it by an arbitrary multiple before casting.

- If you multiply after casting, only 0 will be returned because the decimal point is truncated at the time of casting.

```
//0~Take a random value in the range of 1000
int num4 = (int)(Math.random()*1000);
```

log, log10
`log`

returns the natural logarithm value and` log10`

returns the common logarithm value.

`Math.E`

: The base $ e $ of the natural logarithm. It is defined as a constant.`Math.PI`

(Pi $ π $) is also defined.

```
double num5 = Math.log(Math.E); //num5 = 1.0
double num6 = Math.log10(100); //num6 = 2.0
```

sin, cos, tan Trigonometric method. Enter radians as arguments. ~~ If you want to input the argument of the radian method, you can convert it by multiplying by $ \ frac {π} {180} $. ~~

- Inverse trigonometric functions (asin, etc.) and hyperbolic functions (sinh, etc.) are also available.
(Addition 10/29) If you want to input by the arc degree method, you can use the
`Math.toRadians (double angdeg)`

method to convert it to radians.

```
double num7 = Math.sin(Math.PI/4); //1/Approximate value of √2
double num8 = Math.cos(Math.PI/4); //1/Approximate value of √2
double num9 = Math.tan(Math.toRadians(45));//1(0.9999999999999999)
```

pow Returns a double value that is the power of the first argument to the second argument. Cast if treated as an integer value.

```
double num10 = Math.pow(10, 4); //num10 = 10000.0
```

exp, expm1 The former returns the power value of the base $ e $ of the natural logarithm, and the latter returns the number obtained by subtracting 1 from the former. Let's use it in physics and statistics ...?

```
double num11 = Math.exp(2); // e^2
double num12 = Math.expm1(2);// e^2 -1
```

sqrt, cbrt Returns the square root and cube root.

```
double num13 = Math.sqrt(9); //num13 = 3.0
double num14 = Math.cbrt(64); //num14 = 4.0
```

... I will update it when I find something that I think I will use again.

Recommended Posts