Implementing FMA and finding bugs in C and Rust standard libraries

29 points by itamarst


fanf

Does this bug matter?

Correctly-rounded FMA came up recently as an ingredient in double-double. Of course the followup question is, does double-double matter? And until I read that article I had been under the impression (since the 1990s!) that double-double is probably too expensive to be worthwhile. But iin fact t’s cheaper than software f128!

wezm

To my surprise, musl developers took my bug report seriously.

Curious why it was surprising that the musl folks took the report seriously.

I would not be surprised if the buggy FreeBSD implementation got copy-pasted into lots of different toolchains for various obscure platforms.

I didn't see mention of reporting it to FreeBSD. Given the above it seems like that might be a good idea too.

bakkot

Fun tangentially related fact: there's a (extremely) nascent proposal to add Math.fma to JavaScript.

crusoe

Thanks! I've started to add these test cases to SIMDe and opened an issue to encourage a contribution of these SIMD fallbacks.

https://github.com/simd-everywhere/simde/issues/1440

An additional explanation is at https://drilian.com/posts/2024.12.31-emulating-the-fmadd-instruction-part-1-32-bit-floats/

See also this paper which implemented FMA using round-to-nearest, for platforms where round-to-odd is not available/fast https://doi.org/10.1007/s00211-025-01487-2 (preprint https://hal.science/hal-04575249)