math

math

Numeric math builtin namespace.

Runtime support: native and WebAssembly.

Import

use math;

Functions

FunctionDescription
piReturns the constant pi.
tauReturns the constant tau.
eReturns Euler's number.
epsilonReturns the machine epsilon for floating-point comparisons.
infReturns positive infinity.
neg_infReturns negative infinity.
nanReturns NaN.
absReturns the absolute value of a number.
sqrtReturns the square root of a number.
cbrtReturns the cube root of a number.
expReturns e raised to the given power.
exp2Returns 2 raised to the given power.
lnReturns the natural logarithm of a number.
ln_1pReturns the natural logarithm of one plus a number.
log2Returns the base-2 logarithm of a number.
log10Returns the base-10 logarithm of a number.
sinReturns the sine of an angle in radians.
cosReturns the cosine of an angle in radians.
tanReturns the tangent of an angle in radians.
asinReturns the arcsine of a number.
acosReturns the arccosine of a number.
atanReturns the arctangent of a number.
sinhReturns the hyperbolic sine of a number.
coshReturns the hyperbolic cosine of a number.
tanhReturns the hyperbolic tangent of a number.
floorRounds a number down to the nearest integer value.
ceilRounds a number up to the nearest integer value.
roundRounds a number to the nearest integer value.
truncTruncates the fractional part of a number.
fractReturns the fractional part of a number.
signumReturns the sign of a number.
to_degreesConverts radians to degrees.
to_radiansConverts degrees to radians.
is_nanReturns whether a number is NaN.
is_infiniteReturns whether a number is infinite.
is_finiteReturns whether a number is finite.
atan2Returns the four-quadrant arctangent of two numbers.
powfRaises a number to a floating-point power.
powiRaises a number to an integer power.
hypotReturns the hypotenuse length for two numbers.
logReturns the logarithm of a number for the given base.
minReturns the smaller of two numbers.
maxReturns the larger of two numbers.
copysignReturns the first number with the sign of the second number.
clampClamps a number to an inclusive range.
mul_addComputes 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.