math
Numeric functions and constants for scientific and general-purpose computation.
Import
import mathConstants
math.PI / math.pi - pi (3.14159...) math.E / math.e - Euler's number math.TAU / math.tau - 2 * pi math.INF / math.inf - positive infinity math.NAN / math.nan - not-a-number
Functions
Trigonometry
sin, cos, tan, asin, acos, atan, atan2(y, x), sinh, cosh, tanh, asinh, acosh, atanh - standard trig and hyperbolic functions.
Exponents and logarithms
sqrt(x), cbrt(x), exp(x), expm1(x), log(x), log2(x), log10(x), log1p(x)
Rounding
floor(x), ceil(x), round(x), trunc(x)
Utility
abs(x)- absolute valuepow(x, y)- x raised to yhypot(x, y)- Euclidean distancegcd(a, b)- greatest common divisorlcm(a, b)- least common multiplefactorial(n)- n!clamp(x, lo, hi)- clamp x to [lo, hi]lerp(a, b, t)- linear interpolationsign(x)- -1, 0, or 1degrees(r)/radians(d)- angle conversionfmod(x, y)- floating-point remaindermodf(x)- integer and fractional partscopysign(x, y)- x with sign of yisclose(a, b)- approximate equalityfrexp(x)/ldexp(m, e)- mantissa/exponent split and composecomb(n, k)- n choose kperm(n, k)- n permute k
Predicates
is_nan(x) - true if x is NaN is_inf(x) - true if x is infinite
Aggregate
prod(arr), sum(arr), min(arr), max(arr), mean(arr) - operate on arrays.
Special functions
erf(x), erfc(x), gamma(x), lgamma(x)
Examples
scratch.xs