-
Documentation - https://pkg.go.dev/math
-
The math package provides functions and constants for mathematical operations
-
Common Math Functions
Function Description math.Abs(x)Absolute value math.Sqrt(x)Square root math.Pow(x, y)x raised to the power y math.Pow10(n)10 raised to the power n math.Ceil(x)Smallest integer ≥ x math.Floor(x)Largest integer ≤ x math.Round(x)Round to nearest integer math.Trunc(x)Remove fractional part math.Mod(x, y)Remainder of x / y math.Max(x, y)Maximum of two numbers math.Min(x, y)Minimum of two numbers -
Trigonometric Functions (Angles are in radians, not degrees.)
Function Description math.Sin(x)Sine math.Cos(x)Cosine math.Tan(x)Tangent math.Asin(x)Arc sine math.Acos(x)Arc cosine math.Atan(x)Arc tangent -
Logarithmic Functions
Function Description math.Log(x)Natural logarithm (ln) math.Log10(x)Base-10 logarithm math.Log2(x)Base-2 logarithm math.Exp(x)e^x -
Common Constants
Constant Description math.Piπ (3.14159…) math.EEuler’s number math.Sqrt2√2 math.SqrtPi√π math.Ln2ln(2) math.Ln10ln(10) -
Special Values
Function Description math.NaN()Not a number math.IsNaN(x)Check if value is NaN math.Inf(sign)Positive or negative infinity math.IsInf(x, sign)Check if value is infinity