July 09, 2013 typeid(double) does not respect NaNs | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=7836 Upon closer inspection, however, it seems that this may have been deliberate??? Here's the code from rt/typeinfo/ti_double.d: class TypeInfo_d : TypeInfo { // ... static bool _equals(double f1, double f2) { return f1 == f2 || (f1 !<>= f1 && f2 !<>= f2); } static int _compare(double d1, double d2) { if (d1 !<>= d2) // if either are NaN { if (d1 !<>= d1) { if (d2 !<>= d2) return 0; return -1; } return 1; } return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1); } // ... } It seems as though NaNs are explicitly being checked for, and _equals is made to return true when comparing two NaNs, and some black magic is being used to determine the sign of the comparison in _compare. Why is this? Isn't this a violation of the IEEE floating-point spec?? More to the point, *if* typeinfo isn't meant to match == for whatever reason, then why is it being used as the standard of comparison for AA keys? T -- Don't modify spaghetti code unless you can eat the consequences. |
July 09, 2013 Re: typeid(double) does not respect NaNs | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Tuesday, 9 July 2013 at 03:03:34 UTC, H. S. Teoh wrote:
> More to the point, *if* typeinfo isn't meant to match == for whatever
> reason, then why is it being used as the standard of comparison for AA
> keys?
>
I guess we need NaN == NaN to be true for AA keys, no ?
|
Copyright © 1999-2021 by the D Language Foundation