From b6a1058f24940b59c367b7618bec3405109ccb45 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Sun, 25 Oct 2026 19:55:14 -0500 Subject: [PATCH] Fuse multiply-adds in the Math port on macOS arm64, as Node's build does Node for macOS on arm64 is compiled by clang, which contracts a multiply and an add within one expression into a fused multiply-add. Its sin, cos, tan, asin, acos, atan, sinh, asinh, acosh, atanh, exp, expm1, log, log1p and log10 differ from the unfused results in the last bit for some inputs, so corpus 7717 and 7718 failed on macOS. scr_ieee754.c now sets FP_CONTRACT ON for Apple arm64 targets. Other targets keep it off and compile to the same code as before. --- packages/runtime/src/scr_ieee754.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/runtime/src/scr_ieee754.c b/packages/runtime/src/scr_ieee754.c index 571e3f99a..798bcbcbc 100644 --- a/packages/runtime/src/scr_ieee754.c +++ b/packages/runtime/src/scr_ieee754.c @@ -32,9 +32,16 @@ #include "scr_ieee754.h" -/* Each operation rounds on its own, as in V8's build: no fused - * multiply-add, which would change the results on targets that have one. */ +/* Floating-point contraction follows Node's build of this file. Node for + * macOS on arm64 is compiled by clang, which fuses a multiply and an add + * within one expression into a fused multiply-add; the results differ from + * the unfused ones in the last bit for some inputs. Other builds round each + * operation on its own, as Node's x86-64 builds do. */ +#if defined(__APPLE__) && defined(__aarch64__) +#pragma STDC FP_CONTRACT ON +#else #pragma STDC FP_CONTRACT OFF +#endif static inline uint64_t scr_fd_bits(double d) { uint64_t bits;