IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

math

Defines math utilities.

You can import these APIs from the math package. For example:

from std.math import floor

Traits​

  • ​Absable: The Absable trait describes a type that defines an absolute value operation.
  • ​Ceilable: The Ceilable trait describes a type that defines a ceiling operation.
  • ​CeilDivable: The CeilDivable trait describes a type that defines a ceil division operation.
  • ​CeilDivableRaising: The CeilDivable trait describes a type that define a floor division and negation operation that can raise.
  • ​DivModable: The DivModable trait describes a type that defines division and modulo operations returning both quotient and remainder.
  • ​Floorable: The Floorable trait describes a type that defines a floor operation.
  • ​Powable: The Powable trait describes a type that defines a power operation (i.e. exponentiation) with the same base and exponent types.
  • ​Roundable: The Roundable trait describes a type that defines a rounding operation.
  • ​Truncable: The Truncable trait describes a type that defines a truncation operation.

Functions​

  • ​abs: Get the absolute value of the given object.
  • ​acos: Computes the acos of the inputs.
  • ​acosh: Computes the acosh of the inputs.
  • ​align_down: Returns the closest multiple of alignment that is less than or equal to value, elementwise.
  • ​align_up: Returns the closest multiple of alignment that is greater than or equal to value, elementwise.
  • ​asin: Computes the asin of the inputs.
  • ​asinh: Computes the asinh of the inputs.
  • ​atan: Computes the atan of the inputs.
  • ​atan2: Computes the atan2 of the inputs.
  • ​atanh: Computes the atanh of the inputs.
  • ​cbrt: Computes the cbrt of the inputs.
  • ​ceil: Get the ceiling value of the given object.
  • ​ceildiv: Return the rounded-up result of dividing numerator by denominator.
  • ​clamp: Clamps the values in a SIMD vector to be in a certain range.
  • ​comb: Computes the number of ways to choose k items from n items without repetition and without order (binomial coefficient).
  • ​copysign: Returns a value with the magnitude of the first operand and the sign of the second operand.
  • ​cos: Computes the cos of the inputs.
  • ​cosh: Computes the cosh of the inputs.
  • ​divmod: Performs division and returns the quotient and the remainder.
  • ​erf: Performs the elementwise Erf on a SIMD vector.
  • ​erfc: Computes the erfc of the inputs.
  • ​exp: Calculates elementwise exponential of the input vector.
  • ​exp2: Computes elementwise 2 raised to the power of n, where n is an element of the input SIMD vector.
  • ​exp_approx_f32: Computes a fast approximate e^x for SIMD vectors of 32-bit floats using the base-2 approximation as a backend.
  • ​expm1: Computes the expm1 of the inputs.
  • ​factorial: Computes the factorial of the integer.
  • ​floor: Get the floor value of the given object.
  • ​fma: Performs elementwise fma (fused multiply-add) on the inputs.
  • ​frexp: Breaks floating point values into a fractional part and an exponent part. This follows C and Python in increasing the exponent by 1 and normalizing the fraction from 0.5 to 1.0 instead of 1.0 to 2.0.
  • ​gamma: Computes the Gamma of the input.
  • ​gcd: Compute the greatest common divisor of two integers.
  • ​hypot: Computes the hypot of the inputs.
  • ​iota: Creates a SIMD vector containing an increasing sequence, starting from offset.
  • ​isclose: Returns a boolean SIMD vector indicating which element pairs of a and b are equal within a given tolerance.
  • ​j0: Computes the Bessel function of the first kind of order 0 for each input value.
  • ​j1: Computes the Bessel function of the first kind of order 1 for each input value.
  • ​lcm: Computes the least common multiple of two integers.
  • ​ldexp: Computes elementwise ldexp function.
  • ​lgamma: Computes the lgamma of the inputs.
  • ​log: Performs elementwise natural log (base E) of a SIMD vector.
  • ​log10: Computes the log10 of the inputs.
  • ​log1p: Computes the log1p of the inputs.
  • ​log2: Performs elementwise log (base 2) of a SIMD vector.
  • ​logb: Computes the logb of the inputs.
  • ​max: Performs elementwise maximum of x and y.
  • ​min: Gets the elementwise minimum of x and y.
  • ​modf: Computes the integral and fractional part of the value.
  • ​perm: Computes the number of ways to arrange k items from n items without repetition (permutations).
  • ​pow: Computes the base raised to the power of the exp.
  • ​recip: Performs elementwise reciprocal on a SIMD vector.
  • ​remainder: Computes the remainder of the inputs.
  • ​round: Get the rounded value of the given object.
  • ​rsqrt: Performs elementwise reciprocal square root on a SIMD vector.
  • ​scalb: Computes the scalb of the inputs.
  • ​sin: Computes the sin of the inputs.
  • ​sinh: Computes the sinh of the inputs.
  • ​sqrt: Performs elementwise square root on the elements of a SIMD vector.
  • ​tan: Computes the tan of the inputs.
  • ​tanh: Performs elementwise evaluation of the tanh function.
  • ​trunc: Get the truncated value of the given object.
  • ​ulp: Computes the ULP (units of last place) or (units of least precision) of the number.
  • ​y0: Computes the Bessel function of the second kind of order 0 for each input value.
  • ​y1: Computes the Bessel function of the second kind of order 1 for each input value.