Math
static class Mathimport 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;
}
Inherits from object. Follow these links for inherited members.
Members
Piconst
const double Pi = 3.14159265358979323846The circle constant pi.
Econst
const double E = 2.71828182845904523536The base of natural logarithms.
Tauconst
const double Tau = 6.28318530717958647692One full revolution in radians, 2*pi.
Sinmethod
public static fn Sin<T>(T value) : T where T is realReturns the sine of an angle in radians.
Cosmethod
public static fn Cos<T>(T value) : T where T is realReturns the cosine of an angle in radians.
Tanmethod
public static fn Tan<T>(T value) : T where T is realReturns the tangent of an angle in radians.
Asinmethod
public static fn Asin<T>(T value) : T where T is realReturns inverse sine in radians in [-pi/2, pi/2]; inputs outside [-1, 1] produce NaN.
Acosmethod
public static fn Acos<T>(T value) : T where T is realReturns inverse cosine in radians in [0, pi]; inputs outside [-1, 1] produce NaN.
Atanmethod
public static fn Atan<T>(T value) : T where T is realReturns inverse tangent in radians in [-pi/2, pi/2].
Atan2method
public static fn Atan2<T>(T y, T x) : T where T is realReturns the angle of (x, y) in radians, using both signs to select the quadrant.
SinHmethod
public static fn SinH<T>(T value) : T where T is realReturns hyperbolic sine.
CosHmethod
public static fn CosH<T>(T value) : T where T is realReturns hyperbolic cosine.
TanHmethod
public static fn TanH<T>(T value) : T where T is realReturns hyperbolic tangent.
AsinHmethod
public static fn AsinH<T>(T value) : T where T is realReturns inverse hyperbolic sine.
AcosHmethod
public static fn AcosH<T>(T value) : T where T is realReturns inverse hyperbolic cosine; values below 1 produce NaN.
AtanHmethod
public static fn AtanH<T>(T value) : T where T is realReturns inverse hyperbolic tangent; endpoints -1 and 1 produce signed infinities and values outside that interval produce NaN.
Expmethod
public static fn Exp<T>(T value) : T where T is realReturns e raised to the input power.
Exp2method
public static fn Exp2<T>(T value) : T where T is realReturns 2 raised to the input power.
ExpMinus1method
public static fn ExpMinus1<T>(T value) : T where T is realReturns exp(value) - 1 with an evaluation intended to preserve accuracy near zero.
Logmethod
public static fn Log<T>(T value) : T where T is realReturns the natural logarithm; zero produces negative infinity and negative values produce NaN.
Log2method
public static fn Log2<T>(T value) : T where T is realReturns the base-2 logarithm; zero produces negative infinity and negative values produce NaN.
Log10method
public static fn Log10<T>(T value) : T where T is realReturns the base-10 logarithm; zero produces negative infinity and negative values produce NaN.
LogPlus1method
public static fn LogPlus1<T>(T value) : T where T is realReturns log(1 + value) with an evaluation intended to preserve accuracy near zero.
Powmethod
public static fn Pow<T>(T x, T exponent) : T where T is realReturns x raised to exponent. Negative finite bases require an integral exponent for a real result.
Sqrtmethod
public static fn Sqrt<T>(T value) : T where T is realReturns the nonnegative square root; negative values produce NaN.
CubeRootmethod
public static fn CubeRoot<T>(T value) : T where T is realReturns the real cube root, retaining the sign of negative inputs.
Hypotenusemethod
public static fn Hypotenuse<T>(T x, T y) : T where T is realReturns sqrt(xx + yy), with scaling to avoid unnecessary intermediate overflow or underflow.
Modmethod
public static fn Mod<T>(T x, T y) : T where T is realReturns the remainder after truncating x/y toward zero. A nonzero result has the sign of x; this is not a nonnegative modulo operation.
Remaindermethod
public static fn Remainder<T>(T x, T y) : T where T is realReturns x - n*y where n is x/y rounded to the nearest integer, with ties to even. Differs
from truncating Mod.
Floormethod
public static fn Floor<T>(T value) : T where T is realRounds toward negative infinity, returning the original floating-point type.
Ceilmethod
public static fn Ceil<T>(T value) : T where T is realRounds toward positive infinity, returning the original floating-point type.
Truncmethod
public static fn Trunc<T>(T value) : T where T is realDiscards the fractional part toward zero, preserving signed zero.
Roundmethod
public static fn Round<T>(T value) : T where T is realRounds to the nearest integral value, with halfway cases away from zero. NaN and infinities are returned unchanged.
NearbyRoundmethod
public static fn NearbyRound<T>(T value) : T where T is realRounds to the nearest integral value, with halfway cases to even. NaN and infinities are returned unchanged.
RoundToInt32method
public static fn RoundToInt32<T>(T value) : int32? where T is realRounds to the nearest integer with halfway cases away from zero, returning null for NaN, infinity, or a rounded value outside the target integer range.
RoundToInt64method
public static fn RoundToInt64<T>(T value) : int64? where T is realRounds to the nearest integer with halfway cases away from zero, returning null for NaN, infinity, or a rounded value outside the target integer range.
NearbyRoundToInt32method
public static fn NearbyRoundToInt32<T>(T value) : int32? where T is realRounds to the nearest integer with halfway cases to even, returning null for NaN, infinity, or a rounded value outside the target integer range.
NearbyRoundToInt64method
public static fn NearbyRoundToInt64<T>(T value) : int64? where T is realRounds to the nearest integer with halfway cases to even, returning null for NaN, infinity, or a rounded value outside the target integer range.
Absmethod
public static fn Abs<T>(T value) : T where T is numericReturns 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.
CopySignmethod
public static fn CopySign<T>(T x, T y) : T where T is realReturns the magnitude bits of x with the sign bit of y, including the sign of zero or NaN.
PositiveDiffmethod
public static fn PositiveDiff<T>(T x, T y) : T where T is realReturns x - y when x exceeds y, otherwise positive zero; NaN inputs propagate.
MulAddmethod
public static fn MulAdd<T>(T x, T y, T z) : T where T is realComputes x*y + z with a rounded multiplication followed by a rounded addition. The product rounds to the input type before adding z.
ScaleByPowerOfTwomethod
public static fn ScaleByPowerOfTwo<T>(T value, int32 n) : T where T is realScales value by 2 raised to n, preserving the input floating-point type.
LogExponentmethod
public static fn LogExponent<T>(T value) : T where T is realReturns the unbiased base-2 exponent as a floating-point value. Zero produces negative infinity.
NextRepresentablemethod
public static fn NextRepresentable<T>(T from, T toward) : T where T is realReturns the adjacent representable value from from toward toward. Equal values return
toward, including its zero sign; NaN inputs produce NaN.
IsNaNmethod
public static fn IsNaN<T>(T value) : bool where T is realTests whether the value is NaN.
IsInfinitymethod
public static fn IsInfinity<T>(T value) : bool where T is realTests for either signed infinity.
IsFinitemethod
public static fn IsFinite<T>(T value) : bool where T is realTests that the value is neither infinite nor NaN.
IsNegativemethod
public static fn IsNegative<T>(T value) : bool where T is realTests the sign bit, including negative zero and signed NaNs.
Minmethod
public static fn Min<T>(T a, T b) : T where T is numericReturns the smaller value. Floating-point comparisons select the non-NaN operand when only one is NaN and prefer negative zero when zeros tie.
Maxmethod
public static fn Max<T>(T a, T b) : T where T is numericReturns the larger value. Floating-point comparisons select the non-NaN operand when only one is NaN and prefer positive zero when zeros tie.
Clampmethod
public static fn Clamp<T>(T value, T lo, T hi) : T where T is numericClamps value to [lo, hi]. Supply ordered bounds. A NaN value passes through unchanged.
Lerpmethod
public static fn Lerp<T>(T a, T b, T t) : T where T is realReturns a + t*(b-a). Does not clamp t, so values outside [0, 1] extrapolate.
InverseLerpmethod
public static fn InverseLerp<T>(T a, T b, T value) : T where T is realReturns (value-a)/(b-a) without clamping. Equal endpoints return zero.
Remapmethod
public static fn Remap<T>(T value, T fromLo, T fromHi, T toLo, T toHi) : T where T is realMaps value from one interval to another without clamping. Equal source endpoints return toLo.
SmoothStepmethod
public static fn SmoothStep<T>(T edge0, T edge1, T t) : T where T is realMaps t from the edge interval to [0, 1], clamps, and applies the cubic xx(3-2*x). Equal edges return zero.
SmootherStepmethod
public static fn SmootherStep<T>(T edge0, T edge1, T t) : T where T is realMaps t from the edge interval to [0, 1], clamps, and applies the quintic 6x^5-15x^4+10*x^3. Equal edges return zero.
MoveTowardsmethod
public static fn MoveTowards<T>(T current, T target, T maxDelta) : T where T is realMoves current toward target by at most maxDelta, without overshooting. Supply a nonnegative maxDelta.
Mantissamethod
public static fn Mantissa<T>(T value) : T where T is realReturns the signed fraction from FrExp, whose magnitude for finite nonzero input is in
[0.5, 1).
Fractmethod
public static fn Fract<T>(T value) : T where T is realReturns the fractional part after truncation toward zero, so negative inputs can have negative fractions.
FrExpmethod
public static fn FrExp<T>(T value, out int32 exponent) : T where T is realSplits value into a signed fraction and power-of-two exponent: value = fraction * 2^exponent. Finite nonzero fractions have magnitude in [0.5, 1).
ModFmethod
public static fn ModF<T>(T value, out T integerPart) : T where T is realWrites the integral part truncated toward zero and returns the signed fractional part.
SinCosmethod
public static fn SinCos<T>(T value, out T sinResult, out T cosResult) : void where T is realComputes sine and cosine of the same angle in radians and writes both outputs.
RemainderQuotientmethod
public static fn RemainderQuotient<T>(T x, T y, out int32 quotient) : T where T is realReturns the nearest-even remainder and writes the signed low quotient bits. The quotient output is not the complete potentially large quotient.
Erfmethod
public static fn Erf<T>(T value) : T where T is realReturns the Gaussian error function.
ErfComplementmethod
public static fn ErfComplement<T>(T value) : T where T is realReturns the complementary error function, evaluating the small positive tail directly.
LogGammamethod
public static fn LogGamma<T>(T value) : T where T is realReturns the natural logarithm of the absolute gamma function.
Gammamethod
public static fn Gamma<T>(T value) : T where T is realReturns the gamma function, extending factorial by Gamma(n) = (n-1)! for positive integers.