3 ms·
One thing I did not see mentioned in the article, or in these comments (according to ctrl-f anyway) is the use of feenableexcept()[1] to track down the source o
by smcameron 1y ago
One thing I did not see mentioned in the article, or in these comments (according to ctrl-f anyway) is the use of feenableexcept()[1] to track down the source of NaNs in your code.
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
will cause your code to get a SIGFPE whenever a NaN crawls out from under a rock. Of course it doesn't work with fast-math enabled, but if you're unknowingly getting NaNs without fast-math enabled, you obviously need to fix those before even trying fast-math, and they can be hard to find, and feenableexcept() makes finding them a lot easier.
[1] https://linux.die.net/man/3/feenableexcept https://linux.die.net/man/3/feenableexcept
- DavidVoid 1y agoYeah it's pretty useful to enable every once in a while just to see if anything complains. Be very careful with it in production code though [1]. If you're in a dll then changing the FPU exception flags is a big no-no (unless you're really really careful to restore them when your code goes out of scope). [1]: https://randomascii.wordpress.com/2016/09/16/everything-old-is-new-again-and-a-compiler-bug/ https://randomascii.wordpress.com/2016/09/16/everything-old-...
- jart 1y agoTrapping math is the enlightened way to do things. I wrote an example in the cosmo repo of how to use it. https://github.com/jart/cosmopolitan/blob/master/examples/trapping.c https://github.com/jart/cosmopolitan/blob/master/examples/tr...