3 ms·
> This is not to say that NaNs are a good or bad method, but they're definitely not expensive to implement. I saw him explain that in float, there a too many b
by VikingCoder 9y ago
> This is not to say that NaNs are a good or bad method, but they're definitely not expensive to implement.
I saw him explain that in float, there a too many bit representations that amount to "NaN". According to a Stack Overflow I found:
"IEEE 754 standard defines 16,777,214 32-bit floating point values as NaNs, or 0.4% of all possible values."
That's "expensive" in terms of losing bits of expressiveness that could have been used to represent actual numbers.
- louithethrid 9y agoCost of a NaN Operation on chip- same as every other operation, as NaN just is handled and returned like another floating point value - always resulting in a new NaN value- thus a error invalidates all resulting wrong results. Cost of a Interrupt: 100 ns to 1 microseconds (Quora) Sorry, that solution is simply not interesting for most implementations where floats are used. There are sensors which in realtime hammer out so many values, that not using NaNs means dropping part of your sensor values. This is a classic case of re-inventing a optimal wheel (fine for racing) and not really looking at the use-cases (not fine for a lot of normal day to day driving). Im sure it will bring the groupies on conferences.
- Dylan16807 9y ago> Cost of a Interrupt: 100 ns to 1 microseconds That sounds like the time it takes to do a context switch to the OS. A math error interrupt doesn't need to do a context switch. The cost doesn't need to be any higher than a branch misprediction at 10-20 cycles.
- louithethrid 9y agoI stand corrected, sorry, it was late at night and yes of course its a floating point operation that goes sour, which in assembly would be handled and then the result passed to the programm handling. Still expensive when encountered in mass though, on a micro controler. Thanks for putting it right, before the missinformation could spread.
- geezerjay 9y ago> That's "expensive" in terms of losing bits of expressiveness that could have been used to represent actual numbers. The double precision floating point format already represents between 15 and 17 significant digits, and those who, for some reason, believe they need more expressiveness can already use the illusive and rarely needed 80-bit extended precision floating point format. 0.4% of anything is nothing.