digitalmars.D.learn - Floating point init/nan
- Adam S (7/7) Feb 14 2014 I seem to be having some difficulty with the nan and init
- Adam D. Ruppe (5/6) Feb 14 2014 nan never equals nan, this is in the floating point spec used by
- bearophile (5/6) Feb 14 2014 Additionally, the init NaN doesn't have the same bitpattern as
- Jonathan M Davis (9/14) Feb 15 2014 To be more precise, NaN is never equal to _anything_ - not even itself. ...
I seem to be having some difficulty with the nan and init properties of floating point types. Can anyone explain why the following assertions all fail: assert(float.init == float.nan); assert(float.nan == float.nan); assert(float.init == float.init); Thanks.
Feb 14 2014
On Saturday, 15 February 2014 at 05:18:51 UTC, Adam S wrote:assert(float.init == float.nan);nan never equals nan, this is in the floating point spec used by D, C and others. Use this instead: http://dlang.org/phobos/std_math.html#isNaN
Feb 14 2014
Adam D. Ruppe:nan never equals nan,Additionally, the init NaN doesn't have the same bitpattern as the other. There are many NaNs. Bye, bearophile
Feb 14 2014
On Saturday, February 15, 2014 05:28:05 Adam D. Ruppe wrote:On Saturday, 15 February 2014 at 05:18:51 UTC, Adam S wrote:To be more precise, NaN is never equal to _anything_ - not even itself. Any comparison with NaN as one of the operands results in false - just like any floating point arithmetic with NaN in it results in NaN. The idea is that that way the error which introduced NaN in the first place will propagate and therefore be found rather than being hidden. Sometimes, this is very useful, and sometimes it's a bit annoying, but it's way the IEEE floating point spec says that it's supposed to be. - Jonathan M Davisassert(float.init == float.nan);nan never equals nan, this is in the floating point spec used by D, C and others.
Feb 15 2014