Math
This page contains information about the template functions related to math:
Abs[T Number]( num: T ): T
→ Return the magnitude of num;Avg[T Number]( nums: []T ): float64
→ Return the average of all numbers in the given array nums;Ceil[T Float, R Integer]( num: T ): R
→ Return the mathematical ceil of the given num;Floor[T Float, R Integer]( num: T ): R
→ Return the mathematical floor of the given num;Random[T Integer]( min: T, max: T ): T
→ Generates a random value between the given min and max, there is an error if min < 0, max <= 0 or max <= minRound[T Float, R Integer]( num: T ): R
→ Rounds the given number;Sum[T Number]( nums: []T ): float64
→ Returns the sum of all numbers in nums;Acos[T Float]( num: T ): T
→ Returns the arccosine, in radians;Acosh[T Float]( num: T ): T
→ Returns the inverse hyperbolic cosine;Asin[T Float]( num: T ): T
→ Returns the arcsine, in radians;Asinh[T Float]( num: T ): T
→ Returns the inverse hyperbolic sine;Atan[T Float]( num: T ): T
→ Returns the arctangent, in radians;Atanh[T Float]( num: T ): T
→ Returns the inverse hyperbolic tangent;CubicRoot[T Number]( num: T ): float64
→ Returns the cubic root;Cos[T Float]( num: T ): T
→ Returns the cosine of the radian argument;Cosh[T Float]( num: T ): T
→ Returns the hyperbolic cosine;Gamma[T Float]( num: T ): T
→ Returns the Gamma function of num;IsInf[T Float]( num: T, sign: int ): bool
→ Reports whether num is an infinity, according to sign;IsNaN[T Float]( num: T ): bool
→ Reports whether num is an IEEE 754 “not-a-number” value;Log[T Float]( num: T ): T
→ Returns the natural logarithm;Log10[T Float]( num: T ): T
→ Returns the decimal logarithm;Log2[T Float]( num: T ): T
→ Returns the binary logarithm;Max[T Number]( a: T, b: T ): T
→ Returns the larger of a or b;Min[T Number]( a: T, b: T ): T
→ Returns the smaller of a or b;Power[T Float]( num: T, exp: T ): float64
→ Returns num**exp, the base-num exponential of exp;Sin[T Float]( num: T ): T
→ Returns the sine of the radian argument;Sinh[T Float]( num: T ): T
→ Returns the hyperbolic sine;SquareRoot[T Float]( num: T ): T
→ Returns the square root;Tan[T Float]( num: T ): T
→ Returns the tangent of the radian argument;Tanh[T Float]( num: T ): T
→ Returns the hyperbolic tangent;Trunc[T Float, R Integer]( num: T ): R
→ Returns the integer value, truncating it.
Where Number is the following constraint:
package x
type Number interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64
}
Float is the following constraint:
package x
type Float interface {
~float32 | ~float64
}
And Integer is the following constraint:
package x
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
Note that for operations involving, a Float and returning an Integer, the following situation applies:
- float32 input → This returns an int32;
- float64 input → This returns an int64.