Why do math libraries produce different results across platforms?(github.com)
github.com
Why do math libraries produce different results across platforms?
https://github.com/RegularJoe-CEO/LuxiDemo/releases/tag/v2.0.1
3 comments
Libraries differ in implementation and compilers have freedom to optimize floating point. William K was always furious that the kids don't get it (A nice The Tragically Hip song btw), his rants in his papers are actually entertaining to read and after you are one of the lucky 10000.
I've been working on a problem in quantitative finance where we need reproducible results for audit trails. Simple stuff like sin(0.5) returns different bits on ARM vs x86, or CPU vs GPU.
Traced it down to libm implementations using different polynomial approximations, FMA instructions, and compiler optimizations. Even the same binary can produce different results depending on CPU microarchitecture.
Ended up building a REST API that forces determinism by using fixed Remez polynomial coefficients, disabling FMA, and enforcing strict evaluation order. Every response includes a SHA256 hash of the output bytes.
Just shipped an update with 19 validated unary functions (trig, hyperbolic, exp, log, roots) plus support for compound expressions. Tested across M1 Mac, x86 Linux, and H100 GPU. Same inputs produce identical hashes on all three.
Curious if others have hit this problem. How do you handle determinism in distributed systems where floating point consistency matters? Is there interest in a tool like this or are people just accepting the drift?
Demo binary: https://github.com/RegularJoe-CEO/LuxiDemo/releases/tag/v2.0...
Traced it down to libm implementations using different polynomial approximations, FMA instructions, and compiler optimizations. Even the same binary can produce different results depending on CPU microarchitecture.
Ended up building a REST API that forces determinism by using fixed Remez polynomial coefficients, disabling FMA, and enforcing strict evaluation order. Every response includes a SHA256 hash of the output bytes.
Just shipped an update with 19 validated unary functions (trig, hyperbolic, exp, log, roots) plus support for compound expressions. Tested across M1 Mac, x86 Linux, and H100 GPU. Same inputs produce identical hashes on all three.
Curious if others have hit this problem. How do you handle determinism in distributed systems where floating point consistency matters? Is there interest in a tool like this or are people just accepting the drift?
Demo binary: https://github.com/RegularJoe-CEO/LuxiDemo/releases/tag/v2.0...
[4] https://docs.oracle.com/en/java/javase/21/docs/api/java.base...