Expand description
The Math transcendental functions, ported from V8’s ieee754.cc (itself
Sun’s fdlibm 5.3 plus a few FreeBSD msun routines).
The platform libm is not a substitute: Rust’s f64::sin and friends call
the OS libm, whose results differ from V8’s in the last digit for a few
percent of inputs, and they differ between macOS and Linux. V8 carries its
own copy so Math.cos(0.1) is the same double everywhere; this module is
that copy.
Contraction. Node built by clang for AArch64 compiles each fdlibm
expression with -ffp-contract=on: within ONE C expression, a*b + c and
c - a*b become a single fused multiply-add (llvm.fmuladd, which the
AArch64 backend lowers to fmadd/fmsub). The reference node on the
primary development machine therefore returns different last digits from an
unfused evaluation of the same source — measured: Math.atan differs on
4 of 3600 samples unfused and on 0 fused. Every expression below is written
with mul_add exactly where clang fuses it (the multiply is the left
operand if there is one, else the right; statements are never fused across a
;), so the results are bit-identical to that node. mul_add is a true
fused operation on every target, so the results are also identical across
architectures.