← Standard library

Math

static class Math
import Math from Wax;

Mathematical functions and constants.

Most real-valued operations accept float or double. Generic constraints on each signature describe the accepted types.

import Math from Wax;
api fn Main() : int32 {
    int32 away = Math.RoundToInt32<double>(2.5)!;
    int32 even = Math.NearbyRoundToInt32<double>(2.5)!;
    return away * 10 + even;
}

Math.wax:18

Inherits from object. Follow these links for inherited members.

Members

Piconst

const double Pi = 3.14159265358979323846

The circle constant pi.

Math.wax:24

Econst

const double E = 2.71828182845904523536

The base of natural logarithms.

Math.wax:28

Tauconst

const double Tau = 6.28318530717958647692

One full revolution in radians, 2*pi.

Math.wax:32

Sinmethod

public static fn Sin<T>(T value) : T where T is real

Returns the sine of an angle in radians.

Math.wax:2758

Cosmethod

public static fn Cos<T>(T value) : T where T is real

Returns the cosine of an angle in radians.

Math.wax:2771

Tanmethod

public static fn Tan<T>(T value) : T where T is real

Returns the tangent of an angle in radians.

Math.wax:2784

Asinmethod

public static fn Asin<T>(T value) : T where T is real

Returns inverse sine in radians in [-pi/2, pi/2]; inputs outside [-1, 1] produce NaN.

Math.wax:3322

Acosmethod

public static fn Acos<T>(T value) : T where T is real

Returns inverse cosine in radians in [0, pi]; inputs outside [-1, 1] produce NaN.

Math.wax:3330

Atanmethod

public static fn Atan<T>(T value) : T where T is real

Returns inverse tangent in radians in [-pi/2, pi/2].

Math.wax:3338

Atan2method

public static fn Atan2<T>(T y, T x) : T where T is real

Returns the angle of (x, y) in radians, using both signs to select the quadrant.

Math.wax:3346

SinHmethod

public static fn SinH<T>(T value) : T where T is real

Returns hyperbolic sine.

Math.wax:3356

CosHmethod

public static fn CosH<T>(T value) : T where T is real

Returns hyperbolic cosine.

Math.wax:3364

TanHmethod

public static fn TanH<T>(T value) : T where T is real

Returns hyperbolic tangent.

Math.wax:3372

AsinHmethod

public static fn AsinH<T>(T value) : T where T is real

Returns inverse hyperbolic sine.

Math.wax:3380

AcosHmethod

public static fn AcosH<T>(T value) : T where T is real

Returns inverse hyperbolic cosine; values below 1 produce NaN.

Math.wax:3388

AtanHmethod

public static fn AtanH<T>(T value) : T where T is real

Returns inverse hyperbolic tangent; endpoints -1 and 1 produce signed infinities and values outside that interval produce NaN.

Math.wax:3397

Expmethod

public static fn Exp<T>(T value) : T where T is real

Returns e raised to the input power.

Math.wax:3407

Exp2method

public static fn Exp2<T>(T value) : T where T is real

Returns 2 raised to the input power.

Math.wax:3415

ExpMinus1method

public static fn ExpMinus1<T>(T value) : T where T is real

Returns exp(value) - 1 with an evaluation intended to preserve accuracy near zero.

Math.wax:3423

Logmethod

public static fn Log<T>(T value) : T where T is real

Returns the natural logarithm; zero produces negative infinity and negative values produce NaN.

Math.wax:3432

Log2method

public static fn Log2<T>(T value) : T where T is real

Returns the base-2 logarithm; zero produces negative infinity and negative values produce NaN.

Math.wax:3441

Log10method

public static fn Log10<T>(T value) : T where T is real

Returns the base-10 logarithm; zero produces negative infinity and negative values produce NaN.

Math.wax:3450

LogPlus1method

public static fn LogPlus1<T>(T value) : T where T is real

Returns log(1 + value) with an evaluation intended to preserve accuracy near zero.

Math.wax:3458

Powmethod

public static fn Pow<T>(T x, T exponent) : T where T is real

Returns x raised to exponent. Negative finite bases require an integral exponent for a real result.

Math.wax:3469

Sqrtmethod

public static fn Sqrt<T>(T value) : T where T is real

Returns the nonnegative square root; negative values produce NaN.

Math.wax:3477

CubeRootmethod

public static fn CubeRoot<T>(T value) : T where T is real

Returns the real cube root, retaining the sign of negative inputs.

Math.wax:3489

Hypotenusemethod

public static fn Hypotenuse<T>(T x, T y) : T where T is real

Returns sqrt(xx + yy), with scaling to avoid unnecessary intermediate overflow or underflow.

Math.wax:3502

Modmethod

public static fn Mod<T>(T x, T y) : T where T is real

Returns the remainder after truncating x/y toward zero. A nonzero result has the sign of x; this is not a nonnegative modulo operation.

Math.wax:3517

Remaindermethod

public static fn Remainder<T>(T x, T y) : T where T is real

Returns x - n*y where n is x/y rounded to the nearest integer, with ties to even. Differs from truncating Mod.

Math.wax:3535

Floormethod

public static fn Floor<T>(T value) : T where T is real

Rounds toward negative infinity, returning the original floating-point type.

Math.wax:3543

Ceilmethod

public static fn Ceil<T>(T value) : T where T is real

Rounds toward positive infinity, returning the original floating-point type.

Math.wax:3590

Truncmethod

public static fn Trunc<T>(T value) : T where T is real

Discards the fractional part toward zero, preserving signed zero.

Math.wax:3637

Roundmethod

public static fn Round<T>(T value) : T where T is real

Rounds to the nearest integral value, with halfway cases away from zero. NaN and infinities are returned unchanged.

Math.wax:3671

NearbyRoundmethod

public static fn NearbyRound<T>(T value) : T where T is real

Rounds to the nearest integral value, with halfway cases to even. NaN and infinities are returned unchanged.

Math.wax:3686

RoundToInt32method

public static fn RoundToInt32<T>(T value) : int32? where T is real

Rounds to the nearest integer with halfway cases away from zero, returning null for NaN, infinity, or a rounded value outside the target integer range.

Math.wax:3724

RoundToInt64method

public static fn RoundToInt64<T>(T value) : int64? where T is real

Rounds to the nearest integer with halfway cases away from zero, returning null for NaN, infinity, or a rounded value outside the target integer range.

Math.wax:3748

NearbyRoundToInt32method

public static fn NearbyRoundToInt32<T>(T value) : int32? where T is real

Rounds to the nearest integer with halfway cases to even, returning null for NaN, infinity, or a rounded value outside the target integer range.

Math.wax:3772

NearbyRoundToInt64method

public static fn NearbyRoundToInt64<T>(T value) : int64? where T is real

Rounds to the nearest integer with halfway cases to even, returning null for NaN, infinity, or a rounded value outside the target integer range.

Math.wax:3796

Absmethod

public static fn Abs<T>(T value) : T where T is numeric

Returns the magnitude. For a signed integer minimum, the positive magnitude is unrepresentable and the result remains the negative minimum. Floating-point sign bits are cleared, including for negative zero.

Math.wax:3822

CopySignmethod

public static fn CopySign<T>(T x, T y) : T where T is real

Returns the magnitude bits of x with the sign bit of y, including the sign of zero or NaN.

Math.wax:3866

PositiveDiffmethod

public static fn PositiveDiff<T>(T x, T y) : T where T is real

Returns x - y when x exceeds y, otherwise positive zero; NaN inputs propagate.

Math.wax:3883

MulAddmethod

public static fn MulAdd<T>(T x, T y, T z) : T where T is real

Computes x*y + z with a rounded multiplication followed by a rounded addition. The product rounds to the input type before adding z.

Math.wax:3901

ScaleByPowerOfTwomethod

public static fn ScaleByPowerOfTwo<T>(T value, int32 n) : T where T is real

Scales value by 2 raised to n, preserving the input floating-point type.

Math.wax:3920

LogExponentmethod

public static fn LogExponent<T>(T value) : T where T is real

Returns the unbiased base-2 exponent as a floating-point value. Zero produces negative infinity.

Math.wax:3934

NextRepresentablemethod

public static fn NextRepresentable<T>(T from, T toward) : T where T is real

Returns the adjacent representable value from from toward toward. Equal values return toward, including its zero sign; NaN inputs produce NaN.

Math.wax:3948

IsNaNmethod

public static fn IsNaN<T>(T value) : bool where T is real

Tests whether the value is NaN.

Math.wax:4000

IsInfinitymethod

public static fn IsInfinity<T>(T value) : bool where T is real

Tests for either signed infinity.

Math.wax:4015

IsFinitemethod

public static fn IsFinite<T>(T value) : bool where T is real

Tests that the value is neither infinite nor NaN.

Math.wax:4030

IsNegativemethod

public static fn IsNegative<T>(T value) : bool where T is real

Tests the sign bit, including negative zero and signed NaNs.

Math.wax:4045

Minmethod

public static fn Min<T>(T a, T b) : T where T is numeric

Returns the smaller value. Floating-point comparisons select the non-NaN operand when only one is NaN and prefer negative zero when zeros tie.

Math.wax:4062

Maxmethod

public static fn Max<T>(T a, T b) : T where T is numeric

Returns the larger value. Floating-point comparisons select the non-NaN operand when only one is NaN and prefer positive zero when zeros tie.

Math.wax:4092

Clampmethod

public static fn Clamp<T>(T value, T lo, T hi) : T where T is numeric

Clamps value to [lo, hi]. Supply ordered bounds. A NaN value passes through unchanged.

Math.wax:4125

Lerpmethod

public static fn Lerp<T>(T a, T b, T t) : T where T is real

Returns a + t*(b-a). Does not clamp t, so values outside [0, 1] extrapolate.

Math.wax:4134

InverseLerpmethod

public static fn InverseLerp<T>(T a, T b, T value) : T where T is real

Returns (value-a)/(b-a) without clamping. Equal endpoints return zero.

Math.wax:4141

Remapmethod

public static fn Remap<T>(T value, T fromLo, T fromHi, T toLo, T toHi) : T where T is real

Maps value from one interval to another without clamping. Equal source endpoints return toLo.

Math.wax:4150

SmoothStepmethod

public static fn SmoothStep<T>(T edge0, T edge1, T t) : T where T is real

Maps t from the edge interval to [0, 1], clamps, and applies the cubic xx(3-2*x). Equal edges return zero.

Math.wax:4159

SmootherStepmethod

public static fn SmootherStep<T>(T edge0, T edge1, T t) : T where T is real

Maps t from the edge interval to [0, 1], clamps, and applies the quintic 6x^5-15x^4+10*x^3. Equal edges return zero.

Math.wax:4168

MoveTowardsmethod

public static fn MoveTowards<T>(T current, T target, T maxDelta) : T where T is real

Moves current toward target by at most maxDelta, without overshooting. Supply a nonnegative maxDelta.

Math.wax:4177

Mantissamethod

public static fn Mantissa<T>(T value) : T where T is real

Returns the signed fraction from FrExp, whose magnitude for finite nonzero input is in [0.5, 1).

Math.wax:4189

Fractmethod

public static fn Fract<T>(T value) : T where T is real

Returns the fractional part after truncation toward zero, so negative inputs can have negative fractions.

Math.wax:4198

FrExpmethod

public static fn FrExp<T>(T value, out int32 exponent) : T where T is real

Splits value into a signed fraction and power-of-two exponent: value = fraction * 2^exponent. Finite nonzero fractions have magnitude in [0.5, 1).

Math.wax:4207

ModFmethod

public static fn ModF<T>(T value, out T integerPart) : T where T is real

Writes the integral part truncated toward zero and returns the signed fractional part.

Math.wax:4277

SinCosmethod

public static fn SinCos<T>(T value, out T sinResult, out T cosResult) : void where T is real

Computes sine and cosine of the same angle in radians and writes both outputs.

Math.wax:4337

RemainderQuotientmethod

public static fn RemainderQuotient<T>(T x, T y, out int32 quotient) : T where T is real

Returns the nearest-even remainder and writes the signed low quotient bits. The quotient output is not the complete potentially large quotient.

Math.wax:4346

Erfmethod

public static fn Erf<T>(T value) : T where T is real

Returns the Gaussian error function.

Math.wax:5052

ErfComplementmethod

public static fn ErfComplement<T>(T value) : T where T is real

Returns the complementary error function, evaluating the small positive tail directly.

Math.wax:5060

LogGammamethod

public static fn LogGamma<T>(T value) : T where T is real

Returns the natural logarithm of the absolute gamma function.

Math.wax:5068

Gammamethod

public static fn Gamma<T>(T value) : T where T is real

Returns the gamma function, extending factorial by Gamma(n) = (n-1)! for positive integers.

Math.wax:5076