Math Functions
StevenSwiniarski466 total contributions
Published Jun 9, 2023
Contribute to Docs
Go supports many different math functions through the math
package. The math
package must be imported before using these functions, as in the example below:
package mainimport ("fmt""math")func main() {number := math.Round(-2.55)fmt.Printf("%.1f\n", number)}
Below is a list of math functions usable through the math
package.
Math Functions
- Abs()
- Returns the absolute value of a given number.
- Acos()
- Returns the inverse of the cosine value of a number.
- Acosh()
- Returns the inverse hyperbolic cosine of a number.
- Asin()
- Returns the inverse sine of a number.
- Asinh()
- Returns the inverse hyperbolic sine of a number.
- Atan()
- Returns the arctangent of the given value.
- Cbrt()
- Returns the cube root of a given number of type float64.
- Ceil()
- Returns a given decimal number rounded up to the next highest integer.
- Cos()
- Returns the cosine of the given angle.
- Cosh()
- Returns the hyperbolic cosine of a given value.
- Exp()
- Returns the value of e raised to the power of the parameter x.
- Exp2()
- Returns the value of a base-2 exponential of a given number.
- Floor()
- Returns the given decimal number rounded down to the nearest whole number.
- Hypot()
- Returns the square root of the sum of two squares.
- Log()
- Returns the natural logarithm of a given number.
- Log10()
- Returns the base-10 logarithm of a given number.
- Log2()
- Returns the base-2 logarithm of a given number.
- Max()
- Returns the maximum value of two specified numbers.
- Min()
- Returns the minimum value of two specified numbers.
- Mod()
- Returns the floating-point remainder of dividing x by y.
- Modf()
- Returns the integer and fractional part of a floating-point number.
- Pow()
- Returns the first argument raised to the power of the second argument.
- Remainder()
- Returns the remainder of the division of two given values.
- Round()
- Rounds the given number to the nearest integer.
- Sin()
- Used to calculate the sine of an angle.
- Sinh()
- Returns the hyperbolic sine of the given number.
- Sqrt()
- Returns the square root of a given number.
- Tan()
- Returns the tangent of the given angle.
- Tanh()
- Returns the hyperbolic tangent of a number.
- Trunc()
- Returns the integer value of the given number.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.