logoalt Hacker News

eesmithtoday at 5:00 AM2 repliesview on HN

Do you have checks for non-IEEE 754 math?


Replies

fc417fc802today at 5:24 AM

I do, yes. I check that the compiler reports the desired properties and in cases where my code fails to compile because it does not I special case and manually test each property my code depends on. In my case that's primarily mantissa bit width for the sake of various utility functions that juggle raw FP bits.

Even for "regular" architectures this turns out to be important for FP data types. Long double is an f128 on Emscripten but an f80 on x86_64 Clang, where f128 is provided as __float128. The last time I updated my code (admittedly quite a while ago) Clang version 17 did not (yet?) implement std::numeric_limits support for f128.

Honestly there's no good reason not to test these sorts of assumptions when implementing low level utility functions because it's the sort of stuff you write once and then reuse everywhere forever.

shaknatoday at 5:09 AM

Okay, as the last wasn't obvious enough: C does not do IEEE 754 math.

It is _all_ non-IEEE 754 math.

That it isn't compliant is a compiler guarantee, in the current state of things.

You may as well have an `assert(1)`.

show 1 reply