module std::mathsource
Mathematics over floats (LANGUAGE_SPEC.md section 6.1a).
Float is a lang item: f32 and f64 satisfy it with no marker, through the
float_* extensions below, and the functions take any Float: sqrt(2.0)
is an f32 like any untyped float, const r: f64 = sqrt(2.0) an f64. The externs are the runtime's wrappers over C's
libm, which LLVM turns into single instructions where the target has
them (sqrt, and with SSE4.1 floor, ceil and trunc); the interpreter and
compile-time code call the same functions. min, max, clamp, lerp and
abs take any Number, integers included.
FloatPITAUESQRT_2FRAC_1_SQRT_2FRAC_PI_2FRAC_PI_4LN_2LN_10LOG2_ELOG10_EINFINITYNANsqrtcbrtsincostanasinacosatansinhcoshtanhexponentialexp2loglog2log10floorceilroundtruncatan2powhypotcopysignfmais_nanis_infiniteis_finiteminmaxclampabslerp
interface Floatsource
exp interface Float
What f32 and f64 satisfy, with no marker.
Required functions
fn float_sqrt(self: &) -> Self;fn float_cbrt(self: &) -> Self;fn float_sin(self: &) -> Self;fn float_cos(self: &) -> Self;fn float_tan(self: &) -> Self;fn float_asin(self: &) -> Self;fn float_acos(self: &) -> Self;fn float_atan(self: &) -> Self;fn float_sinh(self: &) -> Self;fn float_cosh(self: &) -> Self;fn float_tanh(self: &) -> Self;fn float_exponential(self: &) -> Self;fn float_exp2(self: &) -> Self;fn float_log(self: &) -> Self;fn float_log2(self: &) -> Self;fn float_log10(self: &) -> Self;fn float_floor(self: &) -> Self;fn float_ceil(self: &) -> Self;fn float_round(self: &) -> Self;fn float_trunc(self: &) -> Self;fn float_abs(self: &) -> Self;fn float_atan2(self: &, x: &Self) -> Self;fn float_pow(self: &, exponent: &Self) -> Self;fn float_hypot(self: &, other: &Self) -> Self;fn float_copysign(self: &, sign: &Self) -> Self;fn float_min(self: &, other: &Self) -> Self;fn float_max(self: &, other: &Self) -> Self;fn float_fma(self: &, factor: &Self, addend: &Self) -> Self;fn float_is_nan(self: &) -> bool;fn float_is_infinite(self: &) -> bool;fn float_is_finite(self: &) -> bool;
const PIsource
exp const PI = 3.141592653589793;
Untyped, so each takes the type it is used at, as a literal does.
const TAUsource
exp const TAU = 6.283185307179586;
const Esource
exp const E = 2.718281828459045;
const SQRT_2source
exp const SQRT_2 = 1.4142135623730951;
const FRAC_1_SQRT_2source
exp const FRAC_1_SQRT_2 = 0.7071067811865476;
const FRAC_PI_2source
exp const FRAC_PI_2 = 1.5707963267948966;
const FRAC_PI_4source
exp const FRAC_PI_4 = 0.7853981633974483;
const LN_2source
exp const LN_2 = 0.6931471805599453;
const LN_10source
exp const LN_10 = 2.302585092994046;
const LOG2_Esource
exp const LOG2_E = 1.4426950408889634;
const LOG10_Esource
exp const LOG10_E = 0.4342944819032518;
const INFINITYsource
exp const INFINITY: f64 = from_bits(0x7FF0000000000000);
Positive infinity and a quiet NaN, as f64 (INFINITY to f32 for f32).
const NANsource
exp const NAN: f64 = from_bits(0x7FF8000000000000);
fn sqrtsource
exp fn sqrt<T: Float>(x: T) -> T
The square root.
fn cbrtsource
exp fn cbrt<T: Float>(x: T) -> T
The cube root.
fn sinsource
exp fn sin<T: Float>(x: T) -> T
The sine of an angle in radians.
fn cossource
exp fn cos<T: Float>(x: T) -> T
The cosine of an angle in radians.
fn tansource
exp fn tan<T: Float>(x: T) -> T
The tangent of an angle in radians.
fn asinsource
exp fn asin<T: Float>(x: T) -> T
The arc sine, in radians.
fn acossource
exp fn acos<T: Float>(x: T) -> T
The arc cosine, in radians.
fn atansource
exp fn atan<T: Float>(x: T) -> T
The arc tangent, in radians.
fn sinhsource
exp fn sinh<T: Float>(x: T) -> T
The hyperbolic sine.
fn coshsource
exp fn cosh<T: Float>(x: T) -> T
The hyperbolic cosine.
fn tanhsource
exp fn tanh<T: Float>(x: T) -> T
The hyperbolic tangent.
fn exponentialsource
exp fn exponential<T: Float>(x: T) -> T
e raised to the value.
fn exp2source
exp fn exp2<T: Float>(x: T) -> T
2 raised to the value.
fn logsource
exp fn log<T: Float>(x: T) -> T
The natural logarithm.
fn log2source
exp fn log2<T: Float>(x: T) -> T
The base-2 logarithm.
fn log10source
exp fn log10<T: Float>(x: T) -> T
The base-10 logarithm.
fn floorsource
exp fn floor<T: Float>(x: T) -> T
The largest whole number not above the value.
fn ceilsource
exp fn ceil<T: Float>(x: T) -> T
The smallest whole number not below the value.
fn roundsource
exp fn round<T: Float>(x: T) -> T
The nearest whole number, halves away from zero.
fn truncsource
exp fn trunc<T: Float>(x: T) -> T
The whole number toward zero.
fn atan2source
exp fn atan2<T: Float>(y: T, x: T) -> T
The angle of the point (x, y), in radians: the arc tangent of y / x in the right quadrant.
fn powsource
exp fn pow<T: Float>(x: T, exponent: T) -> T
The value raised to the exponent.
fn hypotsource
exp fn hypot<T: Float>(x: T, other: T) -> T
The square root of the sum of the squares, without overflow in between.
fn copysignsource
exp fn copysign<T: Float>(x: T, sign: T) -> T
The magnitude with the sign of sign.
fn fmasource
exp fn fma<T: Float>(x: T, factor: T, addend: T) -> T
x * factor + addend, rounded once.
fn is_nansource
exp fn is_nan<T: Float>(x: T) -> bool
fn is_infinitesource
exp fn is_infinite<T: Float>(x: T) -> bool
fn is_finitesource
exp fn is_finite<T: Float>(x: T) -> bool
fn minsource
exp fn min<T: Number>(a: T, b: T) -> T
The smaller value; for floats a NaN gives way to the other.
fn maxsource
exp fn max<T: Number>(a: T, b: T) -> T
The larger value; for floats a NaN gives way to the other.
fn clampsource
exp fn clamp<T: Number>(x: T, low: T, high: T) -> T
The value kept within [low, high].
fn abssource
exp fn abs<T: Number>(x: T) -> T
The magnitude; a float's sign bit cleared, -0.0 and NaNs included.
fn lerpsource
exp fn lerp<T: Number>(a: T, b: T, t: T) -> T
From a at t = 0 to b at t = 1.