std/ffi/libm
libm math primitives. Cross-platform (POSIX + MSVCRT export the
same symbol set). libm is the C math library — historically
distinct from libc (linked -lm on Linux; folded into the CRT on
Windows/macOS), so it lives at std/ffi/libm, a sibling ofstd/ffi/libc, not under it.
The single owning module for the libm transcendental bindings:std/numeric/math consumes these via use std::ffi::libm; and
calls them as libm::sqrt(...). @link(symbol = …) pins each to its bare
libm symbol so the linker resolves it at user-program link time;
the libm:: namespace already disambiguates from the higher-levelstd/numeric/math surface, so the bindings keep their plain names.
Free functions
| Type | Method and description |
|---|---|
| sqrt(x : f64) : f64 Square root of x. Returns NaN for x < 0. |
| cbrt(x : f64) : f64 Real cube root of x (defined for negative x). |
| pow(base : f64, exponent : f64) : f64 base raised to exponent. |
| hypot(x : f64, y : f64) : f64 Euclidean distance sqrt(x*x + y*y), computed without overflow. |
| exp(x : f64) : f64 Base-e exponential e^x. |
| log(x : f64) : f64 Natural (base-e) logarithm of x. Returns NaN for x < 0, -inf at 0. |
| log2(x : f64) : f64 Base-2 logarithm of x. |
| log10(x : f64) : f64 Base-10 logarithm of x. |
| sin(x : f64) : f64 Sine of x, with x in radians. |
| cos(x : f64) : f64 Cosine of x, with x in radians. |
| tan(x : f64) : f64 Tangent of x, with x in radians. |
| asin(x : f64) : f64 Arcsine of x, in radians over [-π/2, π/2]. Domain [-1, 1]. |
| acos(x : f64) : f64 Arccosine of x, in radians over [0, π]. Domain [-1, 1]. |
| atan(x : f64) : f64 Arctangent of x, in radians over (-π/2, π/2). |
| atan2(y : f64, x : f64) : f64 Arctangent of y/x in radians over (-π, π], using the signs of botharguments to select the correct quadrant. |
| sinh(x : f64) : f64 Hyperbolic sine of x. |
| cosh(x : f64) : f64 Hyperbolic cosine of x. |
| tanh(x : f64) : f64 Hyperbolic tangent of x. |
| floor(x : f64) : f64 Largest integral value not greater than x (rounds toward -inf). |
| ceil(x : f64) : f64 Smallest integral value not less than x (rounds toward +inf). |
| trunc(x : f64) : f64 Integral part of x, dropping the fraction (rounds toward zero). |
| round(x : f64) : f64 Nearest integral value to x, rounding halves away from zero. |
| fabs(x : f64) : f64 Absolute value of x. |
| fmod(x : f64, y : f64) : f64 Floating-point remainder of x / y (same sign as x). |
Method detail
#sqrt
Square root of x. Returns NaN for x < 0.
x radicand; domain [0, +inf) for a real result.#cbrt
Real cube root of x (defined for negative x).
x radicand; whole real line.#pow
base raised to exponent.
base the value to raise.exponent the power to raise base to.#hypot
Euclidean distance sqrt(x*x + y*y), computed without overflow.
x first leg length.y second leg length.#exp
Base-e exponential e^x.
x exponent.#log
Natural (base-e) logarithm of x. Returns NaN for x < 0, -inf at 0.
x argument; domain (0, +inf).#log2
Base-2 logarithm of x.
x argument; domain (0, +inf).#log10
Base-10 logarithm of x.
x argument; domain (0, +inf).#sin
Sine of x, with x in radians.
x angle in radians.#cos
Cosine of x, with x in radians.
x angle in radians.#tan
Tangent of x, with x in radians.
x angle in radians.#asin
Arcsine of x, in radians over [-π/2, π/2]. Domain [-1, 1].
x argument; domain [-1, 1].#acos
Arccosine of x, in radians over [0, π]. Domain [-1, 1].
x argument; domain [-1, 1].#atan
Arctangent of x, in radians over (-π/2, π/2).
x argument; whole real line.#atan2
Arctangent of y/x in radians over (-π, π], using the signs of both
arguments to select the correct quadrant.
y numerator (vertical component).x denominator (horizontal component).#sinh
Hyperbolic sine of x.
x argument (a hyperbolic angle, not radians).#cosh
Hyperbolic cosine of x.
x argument (a hyperbolic angle, not radians).#tanh
Hyperbolic tangent of x.
x argument (a hyperbolic angle, not radians).#floor
Largest integral value not greater than x (rounds toward -inf).
x value to round down.#ceil
Smallest integral value not less than x (rounds toward +inf).
x value to round up.#trunc
Integral part of x, dropping the fraction (rounds toward zero).
x value to truncate.#round
Nearest integral value to x, rounding halves away from zero.
x value to round.#fabs
Absolute value of x.
x argument; whole real line.#fmod
Floating-point remainder of x / y (same sign as x).
x dividend.y divisor.