std::math
Constants, the C math library (f64 and f32), and integer arithmetic that reports or clamps overflow. With use std::math; the names read std::sqrt(x), std::PI.
Source: std/math.volt
Functions
std::math::sqrt
fn sqrt(x: f64) -> f64the square root
std::math::cbrt
fn cbrt(x: f64) -> f64the cube root
std::math::pow
fn pow(x: f64, y: f64) -> f64x to the power y
std::math::exp
fn exp(x: f64) -> f64e to the power x
std::math::exp2
fn exp2(x: f64) -> f642 to the power x
std::math::log
fn log(x: f64) -> f64the natural logarithm (base e)
std::math::log2
fn log2(x: f64) -> f64the base-2 logarithm
std::math::log10
fn log10(x: f64) -> f64the base-10 logarithm
std::math::sin
fn sin(x: f64) -> f64the sine of x radians
std::math::cos
fn cos(x: f64) -> f64the cosine of x radians
std::math::tan
fn tan(x: f64) -> f64the tangent of x radians
std::math::asin
fn asin(x: f64) -> f64the arcsine, in radians
std::math::acos
fn acos(x: f64) -> f64the arccosine, in radians
std::math::atan
fn atan(x: f64) -> f64the arctangent, in radians
std::math::atan2
fn atan2(y: f64, x: f64) -> f64the angle of the point (x, y) from the x axis, in radians (-pi to pi)
std::math::sinh
fn sinh(x: f64) -> f64the hyperbolic sine
std::math::cosh
fn cosh(x: f64) -> f64the hyperbolic cosine
std::math::tanh
fn tanh(x: f64) -> f64the hyperbolic tangent
std::math::hypot
fn hypot(x: f64, y: f64) -> f64the length of the hypotenuse, sqrt(x*x + y*y) without overflowing
std::math::floor
fn floor(x: f64) -> f64the largest whole number not above x
std::math::ceil
fn ceil(x: f64) -> f64the smallest whole number not below x
std::math::round
fn round(x: f64) -> f64the nearest whole number, halves away from zero
std::math::trunc
fn trunc(x: f64) -> f64x without its fraction (toward zero)
std::math::fmod
fn fmod(x: f64, y: f64) -> f64the remainder of x / y, with x's sign
std::math::sqrt
fn sqrt(x: f32) -> f32the square root
std::math::cbrt
fn cbrt(x: f32) -> f32the cube root
std::math::pow
fn pow(x: f32, y: f32) -> f32x to the power y
std::math::exp
fn exp(x: f32) -> f32e to the power x
std::math::exp2
fn exp2(x: f32) -> f322 to the power x
std::math::log
fn log(x: f32) -> f32the natural logarithm (base e)
std::math::log2
fn log2(x: f32) -> f32the base-2 logarithm
std::math::log10
fn log10(x: f32) -> f32the base-10 logarithm
std::math::sin
fn sin(x: f32) -> f32the sine of x radians
std::math::cos
fn cos(x: f32) -> f32the cosine of x radians
std::math::tan
fn tan(x: f32) -> f32the tangent of x radians
std::math::asin
fn asin(x: f32) -> f32the arcsine, in radians
std::math::acos
fn acos(x: f32) -> f32the arccosine, in radians
std::math::atan
fn atan(x: f32) -> f32the arctangent, in radians
std::math::atan2
fn atan2(y: f32, x: f32) -> f32the angle of the point (x, y) from the x axis, in radians (-pi to pi)
std::math::sinh
fn sinh(x: f32) -> f32the hyperbolic sine
std::math::cosh
fn cosh(x: f32) -> f32the hyperbolic cosine
std::math::tanh
fn tanh(x: f32) -> f32the hyperbolic tangent
std::math::hypot
fn hypot(x: f32, y: f32) -> f32the length of the hypotenuse, sqrt(x*x + y*y) without overflowing
std::math::floor
fn floor(x: f32) -> f32the largest whole number not above x
std::math::ceil
fn ceil(x: f32) -> f32the smallest whole number not below x
std::math::round
fn round(x: f32) -> f32the nearest whole number, halves away from zero
std::math::trunc
fn trunc(x: f32) -> f32x without its fraction (toward zero)
std::math::fmod
fn fmod(x: f32, y: f32) -> f32the remainder of x / y, with x's sign
std::math::is_nan
<T: type> fn is_nan(x: T) -> boolwhether x is NaN (the only value unequal to itself)
std::math::is_finite
<T: type> fn is_finite(x: T) -> boolwhether x is a number that isn't infinite or NaN (true for every integer)
std::math::is_inf
<T: type> fn is_inf(x: T) -> boolwhether x is positive or negative infinity
std::math::abs
<T: type> fn abs(x: T) -> Tx without its sign (for the most negative integer, that overflows)
std::math::abs
fn abs(x: f64) -> f64x without its sign (-0.0 gives 0.0)
std::math::abs
fn abs(x: f32) -> f32x without its sign (-0.0 gives 0.0)
std::math::min
<T: type> fn min(a: T, b: T) -> Tthe smaller of a and b by < (a when neither is smaller)
std::math::max
<T: type> fn max(a: T, b: T) -> Tthe larger of a and b by < (a when neither is larger)
std::math::clamp
<T: type> fn clamp(x: T, lo: T, hi: T) -> Tx, moved into lo..=hi
std::math::checked_add
<T: type> fn checked_add(a: T, b: T) -> T?a + b, or null when it doesn't fit in T
std::math::checked_sub
<T: type> fn checked_sub(a: T, b: T) -> T?a - b, or null when it doesn't fit in T
std::math::checked_mul
<T: type> fn checked_mul(a: T, b: T) -> T?a * b, or null when it doesn't fit in T
std::math::checked_div
<T: type> fn checked_div(a: T, b: T) -> T?a / b, or null when b is 0 or the quotient doesn't fit (MIN / -1)
std::math::saturating_add
<T: type> fn saturating_add(a: T, b: T) -> Ta + b, or T's largest or smallest value when it doesn't fit
std::math::saturating_sub
<T: type> fn saturating_sub(a: T, b: T) -> Ta - b, or T's largest or smallest value when it doesn't fit
std::math::saturating_mul
<T: type> fn saturating_mul(a: T, b: T) -> Ta * b, or T's largest or smallest value when it doesn't fit
std::math::gcd
<T: type> fn gcd(a: T, b: T) -> Tthe greatest common divisor of a and b, never negative (gcd(0, 0) is 0). Like abs, it overflows only when the answer doesn't fit: gcd(MIN, 0) and gcd(MIN, MIN) of a signed type
std::math::lcm
<T: type> fn lcm(a: T, b: T) -> Tthe least common multiple of a and b, never negative (0 when either is 0)
Methods on other types
Attached to built-in types, or to every type (T).
<T: type> attach fn max_value(static this: T) -> Tthe largest value of integer type T: i32::max_value()
<T: type> attach fn min_value(static this: T) -> Tthe smallest value of integer type T: i32::min_value()
Globals
val PI: f64 = 3.141592653589793val TAU: f64 = 6.283185307179586val E: f64 = 2.718281828459045val SQRT2: f64 = 1.4142135623730951val LN2: f64 = 0.6931471805599453val LN10: f64 = 2.302585092994046val EPSILON: f64 = 2.220446049250313e-16val INF: f64 = over_zero(1.0)val NAN: f64 = over_zero(0.0)