# Programming study diary

October 31, 2020
A brief summary of the main methods of the Math class that handles numbers and how to use each.

# What is a Math class?

A class that summarizes methods for performing numerical processing that can use square roots, exponential functions, logarithmic functions, and so on. The Math class is in the java.lang package, so you don't need to import it.
Below is a summary of how to use the main functions of the Math class.

# abs method

The abs method is a method that calculates the absolute value.

`Basic writing`

```
Absolute value= Math.abs(Target number);
```

Here, one argument of int type, double type, float type, and long type can be entered. (Return value is the same argument type)

# max method and min method

A method for finding the magnitude of a value. Use the max method to find a larger value by comparing numbers, and the min method to find a smaller value.

`Basic writing`

```
Large value= Math.max(Value to compare,Another value to compare);
Small value= Math.min(Value to compare,Another value to compare);
```

Like the abs method, the argument can be one int type, double type, float type, or long type. (Return value is the same argument type)

# ceil method, floor method, round method

Use the ceil method to round up, the floor method to round down, and the round method to round.

`Basic writing`

```
Rounded up value= Math.ceil(Target number);
Rounded down value= Math.floor(Target number);
Rounded value= Math.round(Target number);
```

The argument type can be a double type number, and the return value is also a double type.

# pow method

The pow method is a method for raising values to the power.

`Basic writing`

```
Exponentiation value= Math.pow(bottom,index);
```

Like the ceil method, floor method, and round method, the argument type can be a double type number, and the return value is also a double type.

# sqrt and cbrt methods

The aqrt method is for finding the square root, and the cbrt method is for finding the cube root.

`Basic writing`

```
square root= Math.sqrt(Target numerical value);
Cube root= Math.cbrt(Target numerical value);
```

Like the pow method, the argument type can be a double type number, and the return value is also a double type.

# References

Active engineers explain how to use Java's Math class [for beginners]
Math class