gizlang:math
IEEE 754 primitives and general numerical kernels. import * as Math from "gizlang:math" gives Math.floor(x); sqrt is built in. libm domain errors are NaN, not faults.
import * as Math from "gizlang:math";Types
CompensatedSum
type CompensatedSum = { total: f64; correction: f64; }Compensated linear combination; a refused term leaves the state unchanged.
total:f64correction:f64
Functions
floor
function floor(x: f64): f64 effects {} from "m"The largest integer not greater than X.
ceil
function ceil(x: f64): f64 effects {} from "m"The smallest integer not less than X.
trunc
function trunc(x: f64): f64 effects {} from "m"X without its fraction (rounded toward zero).
fmod
function fmod(x: f64, y: f64): f64 effects {} from "m"The remainder of X divided by Y, with the sign of X (C fmod).
fabs
function fabs(x: f64): f64 effects {} from "m"The absolute value of X.
pow
function pow(x: f64, y: f64): f64 effects {} from "m"X to the power Y.
exp
function exp(x: f64): f64 effects {} from "m"e to the power X.
log
function log(x: f64): f64 effects {} from "m"The natural logarithm of X.
log2
function log2(x: f64): f64 effects {} from "m"The base-2 logarithm of X.
log10
function log10(x: f64): f64 effects {} from "m"The base-10 logarithm of X.
sin
function sin(x: f64): f64 effects {} from "m"The sine of X (radians).
cos
function cos(x: f64): f64 effects {} from "m"The cosine of X (radians).
tan
function tan(x: f64): f64 effects {} from "m"The tangent of X (radians).
asin
function asin(x: f64): f64 effects {} from "m"The arc sine of X, in radians.
acos
function acos(x: f64): f64 effects {} from "m"The arc cosine of X, in radians.
atan
function atan(x: f64): f64 effects {} from "m"The arc tangent of X, in radians.
atan2
function atan2(y: f64, x: f64): f64 effects {} from "m"The angle of the point (X, Y) from the X axis, in radians (-π to π).
hypot
function hypot(x: f64, y: f64): f64 effects {} from "m"The length of the vector (X, Y), without overflow in the squares.
scalbn
function scalbn(x: f64, exponent: i32): f64 effects {} from "m"Scale by an integer power of two without constructing an overflowing intermediate power.
cbrt
function cbrt(x: f64): f64 effects {} from "m"The cube root of X.
sinh
function sinh(x: f64): f64 effects {} from "m"Hyperbolic sine (libm).
cosh
function cosh(x: f64): f64 effects {} from "m"Hyperbolic cosine (libm).
tanh
function tanh(x: f64): f64 effects {} from "m"Hyperbolic tangent (libm).
asinh
function asinh(x: f64): f64 effects {} from "m"Inverse hyperbolic sine (libm).
acosh
function acosh(x: f64): f64 effects {} from "m"Inverse hyperbolic cosine (libm).
atanh
function atanh(x: f64): f64 effects {} from "m"Inverse hyperbolic tangent (libm).
expm1
function expm1(x: f64): f64 effects {} from "m"e**x - 1, exact near 0 (libm).
log1p
function log1p(x: f64): f64 effects {} from "m"log(1 + x), exact near 0 (libm).
rint
function rint(x: f64): f64 effects {} from "m"X rounded to an integer, ties to even (libm).
erf
function erf(x: f64): f64 effects {} from "m"The error function and its complement, Gamma and log|Gamma| (libm).
erfc
function erfc(x: f64): f64 effects {} from "m"The complementary error function, 1 - erf(X).
tgamma
function tgamma(x: f64): f64 effects {} from "m"The gamma function of X.
lgamma
function lgamma(x: f64): f64 effects {} from "m"The natural logarithm of the absolute value of the gamma function of X.
copysign
function copysign(x: f64, y: f64): f64 effects {} from "m"X with the sign of Y (libm).
nextafter
function nextafter(x: f64, y: f64): f64 effects {} from "m"The next double after X toward Y.
abs
function abs(x: f64): f64The absolute value of X.
roundF32
function roundF32(x: f64): f64X rounded to the nearest binary32 value (as an f32 field stores it), as an f64.
Effects: fail.
roundBf16
function roundBf16(x: f64): f64X rounded to the nearest bfloat16 value (ties to even), as an f64.
Effects: fail.
halfBits
function halfBits(x: f64): u64The bits of the IEEE half nearest x (ties to even; finite x below 65520 in magnitude).
Effects: fail.
halfValue
function halfValue(h: u64): f64The value of IEEE half bits h.
Effects: fail.
e4m3Bits
function e4m3Bits(x: f64): u64The FP8 E4M3 (OCP) byte nearest x, as gizhw:kernel stores it: ties to even (below 2^-6 a multiple of 2^-9), saturated at ±448 (0x7E), NaN 0x7F; the sign kept.
Effects: fail.
e4m3Value
function e4m3Value(b: u64): f64The value of FP8 E4M3 (OCP) byte b: bias 7, no infinities, 0x7F and 0xFF NaN.
Effects: fail.
sigmoid
function sigmoid(z: f64): f64The logistic function 1 / (1 + e^-z), without overflow for large |z|.
silu
function silu(x: f64): f64x times its sigmoid, x / (1 + e^-x) (SiLU, swish).
softplus
function softplus(x: f64): f64ln(1 + e^x), x itself above 20 (where they meet in f64 to 1e-9).
isFinite
function isFinite(x: f64): boolTrue for finite IEEE 754 numbers; NaN and both infinities are false.
Effects: fail.
isNaN
function isNaN(x: f64): boolWhether X is NaN, as TypeScript's Number.isNaN.
isInteger
function isInteger(x: f64): boolWhether X is finite and has no fraction, as TypeScript's Number.isInteger.
Effects: fail.
round
function round(x: f64): f64Halves round up, as JavaScript's Math.round (round(-2.5) is -2).
min
function min(a: f64, b: f64): f64The smaller of A and B.
max
function max(a: f64, b: f64): f64The larger of A and B.
minI64
function minI64(a: i64, b: i64): i64The smaller and the larger of two integers.
maxI64
function maxI64(a: i64, b: i64): i64The larger of A and B.
floorDiv
function floorDiv(a: i64, b: i64): i64Integer division rounded toward negative infinity (floorDiv(-1, 86400) is
-1, where / truncates to 0): what day, era or bucket a value falls in.
Effects: fail.
addCompensated
function addCompensated(state: mut CompensatedSum, term: f64): boolAdds TERM to the compensated sum STATE; false, with STATE unchanged, when TERM or the total is not finite.
Effects: fail.
Methods
f64.pow
function f64.pow(self: f64, exponent: f64): f64x ** y (TypeScript's exponent operator, which the parser makes this call): libm pow.
i64.pow
function i64.pow(self: i64, exponent: i64): i64 requires exponent> = 0 { let result = 1n ** e on integers, by squaring. An overflow fails, as * does.
Effects: fail.
Constants
PI
const PI = 3.141592653589793gizlang:math: IEEE 754 primitives and general numerical kernels.
import * as Math from "gizlang:math" gives Math.floor(x); sqrt is
built in. libm domain errors are NaN, not faults.
E
const E = 2.718281828459045Euler's number e.
I64_MAX
const I64_MAX = 9223372036854775807Largest signed 64-bit integer, for arithmetic overflow checks.
F64_EPSILON
const F64_EPSILON = 2.220446049250313e-16The distance from 1.0 to the next f64, 2^-52.
F64_MAX_EXACT_INTEGER
const F64_MAX_EXACT_INTEGER = 9007199254740991The largest integer that an f64 holds exactly, 2^53 - 1.
F64_FRACTION_BITS
const F64_FRACTION_BITS = 52uThe number of fraction bits of an f64.
F64_EXPONENT_MASK
const F64_EXPONENT_MASK = 2047uThe mask of the 11 exponent bits of an f64, after the shift.
F64_FRACTION_MASK
const F64_FRACTION_MASK = 4503599627370495uThe mask of the 52 fraction bits of an f64.
F64_IMPLICIT_BIT
const F64_IMPLICIT_BIT = 4503599627370496uThe implicit leading bit of a normal f64's significand, 2^52.
F64_EXPONENT_BIAS
const F64_EXPONENT_BIAS = 1023The bias of the exponent of an f64.
F64_SUBNORMAL_SCALE
const F64_SUBNORMAL_SCALE = 1022The exponent scale of a subnormal f64.
F64_MIN_QUANTUM_EXPONENT
const F64_MIN_QUANTUM_EXPONENT = -1074The exponent of the smallest positive f64, 2^-1074.