Just another one of those things in programming that have been bothering me a lot.
My Problem
So I have been toying around with this IEEE-754 Floating Point Converter for a while now and I found that, when the exponent is set to its maximum value, a mantissa value of zero will result in positive or negative Infinity (depending on what the sign is set to), and all non-zero mantissa values will result in NaN
(aka Not a Number).
However, is there any specific reason for there being so many NaN
values? Honestly, it just looks like an unnecessary waste of range to me. I get why NaN exists, but it's just a singular value and I've never seen a differentiation between "different kinds" of NaN
anywhere.
My Idea
How about this: If both the exponent and the mantissa are at their maximum values, treat the value as Infinity (whether positive or negative still depends on the sign). This would get rid of the NaN values and almost double the range of the float
and double
types.
But now, where do we put the NaN value? Well, there is one other thing in IEEE-754 Floating Point types that can be achieved by different values: Zero. There is +0
and -0
. They are always treated the same way, so why not discard -0
and consider that to be NaN
? Of course, that would require the processor to always remove the sign whenever something results in 0
, but I think that would make close to no difference in performance.
I know the standard will most likely not change anytime soon, but is there any specific reason why this system wouldn't be better? And to come back to the original question: Is there a reason for such a large chunk of values to be considered NaN
?