logoalt Hacker News

dooglius • today at 2:47 PM • 3 replies • view on HN

FWIW one can configure floating point exceptions at runtime at no overhead, see `man 3 fenv`


Replies

jcranmer • today at 4:21 PM

It's no overhead in the same sense that zero-cost exception-handling is zero-cost: turning them on properly (e.g., #pragma STDC FENV_ACCESS ON or equivalent command-line flags) disables a fair amount of optimizations which incurs an overhead in and of itself.

dzaima • today at 4:14 PM

Except gcc doesn't actually support it to any sane extent (it ignores and warns on "#pragma STDC FENV_ACCESS ON", which C requires for fenv.h to actually function; and as such gcc makes a bunch invalid optimizations); clang supports it, but only as of somewhat-recently.

westurner • today at 3:37 PM

fenv: https://manpages.debian.org/testing/manpages-dev/fenv.3.en.h... :

> These eleven functions were defined in C99, and describe the handling of floating-point rounding and exceptions (overflow, zero-divide, etc.).