Skip to content

std::math

Status: experimental

Mathematical constants and f64 functions (Go's math package shape).

API details and source

The implementation source contains the complete declarations and implementation notes. The table below lists canonical Gossamer call signatures; every item name links directly to its implementation file.

Item Canonical signature or declaration Description
E const E: f64 Euler's number e.
INF const INF: f64 Positive infinity.
LN_10 const LN_10: f64 Natural log of 10.
LN_2 const LN_2: f64 Natural log of 2.
LOG10_E const LOG10_E: f64 Base-10 logarithm of e.
LOG2_E const LOG2_E: f64 Base-2 logarithm of e.
MAX_F64 const MAX_F64: f64 Largest finite f64 value.
MIN_POSITIVE_F64 const MIN_POSITIVE_F64: f64 Smallest positive normal f64 value.
NAN const NAN: f64 Not-a-number value.
NEG_INF const NEG_INF: f64 Negative infinity.
PHI const PHI: f64 Golden ratio φ.
PI const PI: f64 Archimedes' constant π.
SQRT_2 const SQRT_2: f64 √2.
abs fn abs(x: f64) -> f64 Absolute value of x.
acos fn acos(x: f64) -> f64 Arccosine (radians).
asin fn asin(x: f64) -> f64 Arcsine (radians).
atan fn atan(x: f64) -> f64 Arctangent (radians).
atan2 fn atan2(y: f64, x: f64) -> f64 Four-quadrant arctangent of y/x.
Int type Int Arbitrary-precision signed integer.
Uint type Uint Arbitrary-precision unsigned integer.
factorial fn factorial(n: i64) -> big::Uint Computes n! as an Int.
int_abs fn int_abs(value: big::Int) -> big::Int Absolute value of an Int.
int_add fn int_add(a: big::Int, b: big::Int) -> big::Int Sum of two Ints.
int_cmp fn int_cmp(a: big::Int, b: big::Int) -> i64 Three-way comparison of two Ints (-1, 0, 1).
int_div fn int_div(a: big::Int, b: big::Int) -> big::Int Truncated quotient of two Ints.
int_from_i64 fn int_from_i64(value: i64) -> big::Int Converts an i64 into an Int.
int_from_str fn int_from_str(text: String) -> Result<big::Int, errors::Error> Parses a decimal string into an Int.
int_gcd fn int_gcd(a: big::Int, b: big::Int) -> big::Int Greatest common divisor of two Ints.
int_is_negative fn int_is_negative(value: big::Int) -> bool Reports whether the Int is less than zero.
int_is_positive fn int_is_positive(value: big::Int) -> bool Reports whether the Int is greater than zero.
int_is_zero fn int_is_zero(value: big::Int) -> bool Reports whether the Int is zero.
int_lcm fn int_lcm(a: big::Int, b: big::Int) -> big::Int Least common multiple of two Ints.
int_mul fn int_mul(a: big::Int, b: big::Int) -> big::Int Product of two Ints.
int_neg fn int_neg(value: big::Int) -> big::Int Negation of an Int.
int_pow fn int_pow(value: big::Int, exp: i64) -> big::Int Int raised to a non-negative power.
int_rem fn int_rem(a: big::Int, b: big::Int) -> big::Int Remainder of two Ints.
int_sub fn int_sub(a: big::Int, b: big::Int) -> big::Int Difference of two Ints.
int_to_hex fn int_to_hex(value: big::Int) -> String Hexadecimal string form of an Int.
int_to_i64 fn int_to_i64(value: big::Int) -> Result<i64, errors::Error> Narrows an Int to i64 where it fits.
int_to_str fn int_to_str(value: big::Int) -> String Decimal string form of an Int.
uint_add fn uint_add(a: big::Uint, b: big::Uint) -> big::Uint Sum of two Uints.
uint_bit_len fn uint_bit_len(value: big::Uint) -> i64 Number of significant bits in a Uint.
uint_from_str fn uint_from_str(text: String) -> Result<big::Uint, errors::Error> Parses a decimal string into a Uint.
uint_from_u64 fn uint_from_u64(value: u64) -> big::Uint Converts a u64 into a Uint.
uint_is_zero fn uint_is_zero(value: big::Uint) -> bool Reports whether the Uint is zero.
uint_mul fn uint_mul(a: big::Uint, b: big::Uint) -> big::Uint Product of two Uints.
uint_pow fn uint_pow(value: big::Uint, exp: i64) -> big::Uint Uint raised to a non-negative power.
uint_pow_mod fn uint_pow_mod(value: big::Uint, exp: big::Uint, modulus: big::Uint) -> big::Uint Modular exponentiation of a Uint.
uint_to_hex fn uint_to_hex(value: big::Uint) -> String Hexadecimal string form of a Uint.
uint_to_str fn uint_to_str(value: big::Uint) -> String Decimal string form of a Uint.
uint_to_u64 fn uint_to_u64(value: big::Uint) -> Result<u64, errors::Error> Narrows a Uint to u64 where it fits.
add fn add(x: u64, y: u64, carry: u64) -> (u64, u64) x + y + carry; returns (sum, carry_out).
count_ones fn count_ones(x: u64) -> i64 Number of set bits (popcount).
count_zeros fn count_zeros(x: u64) -> i64 Number of clear bits.
div fn div(hi: u64, lo: u64, y: u64) -> (u64, u64) 128-bit dividend / 64-bit divisor; returns (quotient, remainder).
leading_zeros fn leading_zeros(x: u64) -> i64 Leading zero bit count.
len fn len(x: u64) -> i64 Minimum bits required to represent x.
mul fn mul(x: u64, y: u64) -> (u64, u64) Full 128-bit product; returns (hi, lo).
reverse_bits fn reverse_bits(x: u64) -> i64 Reverses bit order of x.
reverse_bytes fn reverse_bytes(x: u64) -> i64 Reverses byte order of x.
rotate_left fn rotate_left(x: u64, n: i64) -> u64 Rotates x left by n bits.
rotate_right fn rotate_right(x: u64, n: i64) -> u64 Rotates x right by n bits.
sub fn sub(x: u64, y: u64, borrow: u64) -> (u64, u64) x - y - borrow; returns (diff, borrow_out).
trailing_zeros fn trailing_zeros(x: u64) -> i64 Trailing zero bit count.
cbrt fn cbrt(x: f64) -> f64 Cube root.
ceil fn ceil(x: f64) -> f64 Smallest integer ≥ x.
clamp fn clamp(x: f64, min: f64, max: f64) -> f64 Constrain x to the inclusive range [lo, hi].
copysign fn copysign(x: f64, y: f64) -> f64 Magnitude of x with sign of y.
cos fn cos(x: f64) -> f64 Cosine (radians).
cosh fn cosh(x: f64) -> f64 Hyperbolic cosine.
exp fn exp(x: f64) -> f64 e^x.
exp2 fn exp2(x: f64) -> f64 2^x.
floor fn floor(x: f64) -> f64 Largest integer ≤ x.
hypot fn hypot(x: f64, y: f64) -> f64 Euclidean distance √(x²+y²).
is_inf fn is_inf(x: f64, sign: i64) -> bool Reports whether x is infinite.
is_nan fn is_nan(x: f64) -> bool Reports whether x is NaN.
ln fn ln(x: f64) -> f64 Natural logarithm.
log fn log(x: f64, y: f64) -> f64 Logarithm with given base.
log10 fn log10(x: f64) -> f64 Base-10 logarithm.
log2 fn log2(x: f64) -> f64 Base-2 logarithm.
max fn max(x: f64, y: f64) -> f64 Greater of two values.
min fn min(x: f64, y: f64) -> f64 Lesser of two values.
positive_diff fn positive_diff(x: f64, y: f64) -> f64 max(x-y, 0).
pow fn pow(x: f64, y: f64) -> f64 x raised to the power y.
Rng type Rng SplitMix64-based RNG.
rem fn rem(x: f64, y: f64) -> f64 Floating-point remainder x%y.
round fn round(x: f64) -> f64 Nearest integer, half away from zero.
sin fn sin(x: f64) -> f64 Sine (radians).
sinh fn sinh(x: f64) -> f64 Hyperbolic sine.
sqrt fn sqrt(x: f64) -> f64 Square root.
tan fn tan(x: f64) -> f64 Tangent (radians).
tanh fn tanh(x: f64) -> f64 Hyperbolic tangent.
trunc fn trunc(x: f64) -> f64 Integer part of x.