When GCC’s “-ffast-math” isn’t
programerror.com
programerror.com
It would be interesting to separate these two effects. You can get the former by /compiling/ with --ffast-math and the latter by /linking/ with -ffast-math.
BTW, to all the library writers out there: never ever link a shared library with -ffast-math. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55522
>>> s = '4.74303020008e-322'
>>> f = float(s)
>>> print(str(f))
4.74303020008e-322
>>> import osgeo
>>> print(str(f))
0.0One of the things that happens when you enable "unsafe" options is that it sets a flag in the SSE control register to set subnormal numbers to zero. Because subnormal numbers slow things down considerably, making them not happen is one of the unsafe ways to speed up code. Importing that library will run initialization code that sets the control register to get the extra, precision-losing, speed, and as a consequence, set all those tiny numbers to zero, hence the results you see.
[1] https://en.wikipedia.org/wiki/Denormal_number
[2] http://www.binaryconvert.com/result_double.html?decimal=0520...
Despite the title, which promises an article with some interesting technical depth, I just don't feel like I learned anything. On the whole the piece comes off like a glib anecdote; lazy and not very informative.