JavaScript's number semantics where they differ from Elixir's.
Math.round (halves up, toward +infinity), % (the dividend's sign),
Math.fround, typed-array stores (u8/1, clamp_u8/1, i8/1, ...),
Number.prototype.toFixed and String(number), V8's Math.hypot (which
scales and sums with Kahan's compensation), and two functions :math does
not have, Math.cbrt and Math.log1p, as fdlibm computes them. All of
these agree with V8 bit for bit.
For Math.sin, Math.exp, Math.pow and the other transcendental
functions the pieces call :math directly. It uses the platform's libm,
which can differ from V8's fdlibm in the last bit for a few percent of
inputs; a character rarely sits that close to a threshold, and every
piece's golden frames still match upstream's (see PORTING.md).
Erlang floats have no infinity and no NaN. Where JS would answer with one,
these functions raise ArithmeticError, as :math and Erlang arithmetic
do, and the pieces guard such cases where upstream relies on them.
Rounding functions (round/1, floor/1, ceil/1, trunc/1) return
integers, which is what the pieces index with.
Summary
Functions
Math.cbrt (fdlibm).
Math.ceil, as an integer.
A write to a Uint8ClampedArray: clamped to 0..255, halves to even.
Math.floor, as an integer.
Math.fround: the nearest single-precision value, as a Float32Array stores it.
Math.hypot, as V8 computes it: each term scaled by the largest and summed
with Kahan's compensation. Not the same bits as sqrt(a*a + b*b).
Math.hypot of three numbers: hypot_list/1's steps, unrolled.
Math.hypot of any count of numbers.
A write to an Int8Array.
A write to an Int16Array.
Math.log1p (fdlibm).
JS %: the remainder of truncated division, with the dividend's sign
(C's fmod). Integers stay integers.
Math.round: halves round up, toward +infinity. Returns an integer.
Math.sign: -1, 0 or 1.
Math.sqrt, exactly rounded on every platform.
Number.prototype.toFixed: rounds the exact binary value, halves away from
zero, which is not what :erlang.float_to_binary/2 does on a tie.
String(x) for a number: the shortest digits that read back as x, laid out as JS does.
Math.trunc, as an integer.
A write to a Uint8Array: truncated, then wrapped modulo 256.
A write to a Uint16Array.
Functions
Math.cbrt (fdlibm).
Math.ceil, as an integer.
@spec clamp_u8(x :: number()) :: 0..255
A write to a Uint8ClampedArray: clamped to 0..255, halves to even.
Math.floor, as an integer.
Math.fround: the nearest single-precision value, as a Float32Array stores it.
Math.hypot, as V8 computes it: each term scaled by the largest and summed
with Kahan's compensation. Not the same bits as sqrt(a*a + b*b).
Math.hypot of three numbers: hypot_list/1's steps, unrolled.
Math.hypot of any count of numbers.
@spec i8(x :: number()) :: -128..127
A write to an Int8Array.
@spec i16(x :: number()) :: -32768..32767
A write to an Int16Array.
Math.log1p (fdlibm).
JS %: the remainder of truncated division, with the dividend's sign
(C's fmod). Integers stay integers.
Math.round: halves round up, toward +infinity. Returns an integer.
@spec sign(x :: number()) :: -1 | 0 | 1
Math.sign: -1, 0 or 1.
Math.sqrt, exactly rounded on every platform.
@spec to_fixed(x :: number(), digits :: non_neg_integer()) :: String.t()
Number.prototype.toFixed: rounds the exact binary value, halves away from
zero, which is not what :erlang.float_to_binary/2 does on a tie.
String(x) for a number: the shortest digits that read back as x, laid out as JS does.
Math.trunc, as an integer.
@spec u8(x :: number()) :: 0..255
A write to a Uint8Array: truncated, then wrapped modulo 256.
@spec u16(x :: number()) :: 0..65535
A write to a Uint16Array.