5 ms·
Nit: > Multiplying infinity by any number is defined to be a NaN for IEEE 754 No, multiplying infinity by any number other than zero or NaN produces an infini
by stephencanon 5y ago
Nit:
> Multiplying infinity by any number is defined to be a NaN for IEEE 754
No, multiplying infinity by any number other than zero or NaN produces an infinity. Multiplying infinity by zero produces a NaN.
- mirekrusin 5y agoMultiplying infinity by negative number (including negative infinity) gives -Infinity, no?
- scatters 5y agoWell, other than negative zero.
- mirekrusin 5y agoTrue :)
- stephencanon 5y agoCorrect, hence "an infinity" (also, infinity * -0 is NaN).
- chipsa 5y agoInfinity is a special type of NaN where the fraction component is all 0.
- Dylan16807 5y agoI'm pretty sure that's just a storage optimization and not one being a subset of the other.
- quietbritishjim 5y agoFor example: nan==nan is false but inf==inf is true
- klodolph 5y agoIt's not actually a storage optimization. A number is either NaN (mantissa != 0) or Inf (mantissa == 0).
- quietbritishjim 5y agoI think they meant that having the same exponent, even though they are logically different numbers, is a storage optimisation.
- Dylan16807 5y agoWhat's your definition of storage optimization, where zero and nonzero mantissas meaning completely different things doesn't qualify?
- klodolph 5y agoZero and nonzero mantissas always mean different things, no matter what the exponent is. I guess I am not sure how this could be described as an optimization... an optimization relative to what? Some hypothetical floating-point format which has extra bits?
- Dylan16807 5y ago> Zero and nonzero mantissas always mean different things, no matter what the exponent is. They don't normally mean different types of value. 4.0000000 and 4.0000001 are just different adjacent numbers. > I guess I am not sure how this could be described as an optimization... an optimization relative to what? Some hypothetical floating-point format which has extra bits? Using the exponent to distinguish, like the format uses for normal/subnormal/nonfinite. Or using extra bits, sure. They took a bit pattern that would have been a NaN if not for Infinity, and used it to store Infinity.
- stephencanon 5y agoInfinity is not a special type of NaN. Infinity and NaN are encoded with the same exponent, but they are distinct numerical data.
- klodolph 5y agoYou might think of floating-point numbers coming in five varieties: - normal (exponent not minimum or maximum) - zero (minimum exponent, mantissa == 0) - subnormal (minimum exponent, mantissa != 0) - infinity (maximum exponent, mantissa == 0) - nan (maxmimum exponent, mantissa != 0) NaN is only the last category, strictly. Finite is everything except infinity and nan. Subnormal and zero are collectively denormal. The distinction between "subnormal" and "denormal" is a bit esoteric.
- mananaysiempre 5y agoFurther nit: > The calculation was using the HUGE_VAL constant, which is defined as an ISO C constant with a value of positive infinity [...]. Only if the floating point implementation has infinities, which ISO C does not require. C99 also defines INFINITY, but that one’s also not required to actually be an infinity, unfortunately. More seriously: > "Nowadays, outside museums, it's hard to find computers which don't implement IEEE 754." AFAIU there are plenty of implementations that either run faster without or outright refuse to implement the “gradual underflow” semantics, which 754 technically requires with no equivocation. (Wikipedia tells me the Intel compiler turns on SSE “denormals as zeros” when optimizations are on, for example.)
- WalterBright 5y agoI appreciate a guy who knows his NaNs!