math
math
Numeric math builtin namespace.
Runtime support: native and WebAssembly.
Import
use math;
Functions
| Function | Description |
|---|---|
pi | Returns the constant pi. |
tau | Returns the constant tau. |
e | Returns Euler's number. |
epsilon | Returns the machine epsilon for floating-point comparisons. |
inf | Returns positive infinity. |
neg_inf | Returns negative infinity. |
nan | Returns NaN. |
abs | Returns the absolute value of a number. |
sqrt | Returns the square root of a number. |
cbrt | Returns the cube root of a number. |
exp | Returns e raised to the given power. |
exp2 | Returns 2 raised to the given power. |
ln | Returns the natural logarithm of a number. |
ln_1p | Returns the natural logarithm of one plus a number. |
log2 | Returns the base-2 logarithm of a number. |
log10 | Returns the base-10 logarithm of a number. |
sin | Returns the sine of an angle in radians. |
cos | Returns the cosine of an angle in radians. |
tan | Returns the tangent of an angle in radians. |
asin | Returns the arcsine of a number. |
acos | Returns the arccosine of a number. |
atan | Returns the arctangent of a number. |
sinh | Returns the hyperbolic sine of a number. |
cosh | Returns the hyperbolic cosine of a number. |
tanh | Returns the hyperbolic tangent of a number. |
floor | Rounds a number down to the nearest integer value. |
ceil | Rounds a number up to the nearest integer value. |
round | Rounds a number to the nearest integer value. |
trunc | Truncates the fractional part of a number. |
fract | Returns the fractional part of a number. |
signum | Returns the sign of a number. |
to_degrees | Converts radians to degrees. |
to_radians | Converts degrees to radians. |
is_nan | Returns whether a number is NaN. |
is_infinite | Returns whether a number is infinite. |
is_finite | Returns whether a number is finite. |
atan2 | Returns the four-quadrant arctangent of two numbers. |
powf | Raises a number to a floating-point power. |
powi | Raises a number to an integer power. |
hypot | Returns the hypotenuse length for two numbers. |
log | Returns the logarithm of a number for the given base. |
min | Returns the smaller of two numbers. |
max | Returns the larger of two numbers. |
copysign | Returns the first number with the sign of the second number. |
clamp | Clamps a number to an inclusive range. |
mul_add | Computes a fused multiply-add operation. |
Function details
pi
fn pi() -> float
Returns the constant pi.
tau
fn tau() -> float
Returns the constant tau.
e
fn e() -> float
Returns Euler's number.
epsilon
fn epsilon() -> float
Returns the machine epsilon for floating-point comparisons.
inf
fn inf() -> float
Returns positive infinity.
neg_inf
fn neg_inf() -> float
Returns negative infinity.
nan
fn nan() -> float
Returns NaN.
abs
fn abs(value: number) -> number
Returns the absolute value of a number.
sqrt
fn sqrt(value: number) -> float
Returns the square root of a number.
cbrt
fn cbrt(value: number) -> float
Returns the cube root of a number.
exp
fn exp(value: number) -> float
Returns e raised to the given power.
exp2
fn exp2(value: number) -> float
Returns 2 raised to the given power.
ln
fn ln(value: number) -> float
Returns the natural logarithm of a number.
ln_1p
fn ln_1p(value: number) -> float
Returns the natural logarithm of one plus a number.
log2
fn log2(value: number) -> float
Returns the base-2 logarithm of a number.
log10
fn log10(value: number) -> float
Returns the base-10 logarithm of a number.
sin
fn sin(value: number) -> float
Returns the sine of an angle in radians.
cos
fn cos(value: number) -> float
Returns the cosine of an angle in radians.
tan
fn tan(value: number) -> float
Returns the tangent of an angle in radians.
asin
fn asin(value: number) -> float
Returns the arcsine of a number.
acos
fn acos(value: number) -> float
Returns the arccosine of a number.
atan
fn atan(value: number) -> float
Returns the arctangent of a number.
sinh
fn sinh(value: number) -> float
Returns the hyperbolic sine of a number.
cosh
fn cosh(value: number) -> float
Returns the hyperbolic cosine of a number.
tanh
fn tanh(value: number) -> float
Returns the hyperbolic tangent of a number.
floor
fn floor(value: number) -> number
Rounds a number down to the nearest integer value.
ceil
fn ceil(value: number) -> number
Rounds a number up to the nearest integer value.
round
fn round(value: number) -> number
Rounds a number to the nearest integer value.
trunc
fn trunc(value: number) -> number
Truncates the fractional part of a number.
fract
fn fract(value: number) -> float
Returns the fractional part of a number.
signum
fn signum(value: number) -> number
Returns the sign of a number.
to_degrees
fn to_degrees(value: number) -> float
Converts radians to degrees.
to_radians
fn to_radians(value: number) -> float
Converts degrees to radians.
is_nan
fn is_nan(value: number) -> bool
Returns whether a number is NaN.
is_infinite
fn is_infinite(value: number) -> bool
Returns whether a number is infinite.
is_finite
fn is_finite(value: number) -> bool
Returns whether a number is finite.
atan2
fn atan2(y: number, x: number) -> float
Returns the four-quadrant arctangent of two numbers.
powf
fn powf(value: number, exponent: number) -> float
Raises a number to a floating-point power.
powi
fn powi(value: number, exponent: int) -> float
Raises a number to an integer power.
hypot
fn hypot(left: number, right: number) -> float
Returns the hypotenuse length for two numbers.
log
fn log(value: number, base: number) -> float
Returns the logarithm of a number for the given base.
min
fn min(left: number, right: number) -> number
Returns the smaller of two numbers.
max
fn max(left: number, right: number) -> number
Returns the larger of two numbers.
copysign
fn copysign(value: number, sign: number) -> float
Returns the first number with the sign of the second number.
clamp
fn clamp(value: number, min: number, max: number) -> number
Clamps a number to an inclusive range.
mul_add
fn mul_add(left: number, right: number, addend: number) -> float
Computes a fused multiply-add operation.