The documentation (in the standards) for all of fenv.h
is rather confusing, but I'm especially confused about feholdexcept
and the concept of "non-stop mode" for a floating point exception. As far as I can tell, on any IEEE floating point implementation, exceptions are non-signaling/"non-stop" by default, and the fenv.h
interfaces seem to provide no way to enable a signaling mode unless it was the default. Is the whole concept of feholdexcept
useless except on non-IEEE systems or systems with nonstandard extensions for setting the signaling exception mask?
Suppose that you're implementing a library, and you don't know anything about what your callers might do the the floating-point environment before calling your code. They might unmask an exception, and install a custom trap handler that causes division-by-zero to produce the value 42. Suppose that your library depends on having default IEEE-754 behavior for division-by-zero. The feholdexcept
function gives you a means to enforce this behavior. The caller's environment, complete with their unmasked exception, can then be restored using the fesetenv
function.
This is admittedly a fairly obscure corner case of usage, but frankly everything in fenv.h
is fairly obscure to most programmers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With