digitalmars.D - typeid(double) does not respect NaNs
- H. S. Teoh (37/37) Jul 08 2013 http://d.puremagic.com/issues/show_bug.cgi?id=7836
- deadalnix (2/7) Jul 08 2013 I guess we need NaN == NaN to be true for AA keys, no ?
- H. S. Teoh (6/13) Jul 09 2013 Not according to: http://d.puremagic.com/issues/show_bug.cgi?id=7836
- Maxim Fomin (4/18) Jul 09 2013 I think it was not decided yet. From language coherency point of
- Jonathan M Davis (9/31) Jul 09 2013 I'd think that having NaN != NaN would cause serious problems with retri...
- bearophile (5/6) Jul 09 2013 Here I'd like D AAs act as Python dicts. This means breaking
- Jonathan M Davis (7/12) Jul 09 2013 I'm afraid that you'll have to be more specific in terms of what you mea...
- bearophile (5/9) Jul 09 2013 OK.
- monarch_dodra (7/24) Jul 09 2013 Using floating point as keys can make sense in an ordered
- deadalnix (2/43) Jul 09 2013 That what I meant, and you explained it much better.
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.
Jul 08 2013
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 ?
Jul 08 2013
On Tue, Jul 09, 2013 at 08:05:35AM +0200, deadalnix wrote:On Tuesday, 9 July 2013 at 03:03:34 UTC, H. S. Teoh wrote:Not according to: http://d.puremagic.com/issues/show_bug.cgi?id=7836 So, should NaN == NaN for AA keys, or not? T -- Never ascribe to malice that which is adequately explained by incompetence. -- Napoleon BonaparteMore 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 ?
Jul 09 2013
On Tuesday, 9 July 2013 at 13:46:48 UTC, H. S. Teoh wrote:On Tue, Jul 09, 2013 at 08:05:35AM +0200, deadalnix wrote:I think it was not decided yet. From language coherency point of view NaN != NaN like in general case, from usefulness perspective you don't need several nans in AA array.On Tuesday, 9 July 2013 at 03:03:34 UTC, H. S. Teoh wrote:Not according to: http://d.puremagic.com/issues/show_bug.cgi?id=7836 So, should NaN == NaN for AA keys, or not? TMore 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 ?
Jul 09 2013
On Tuesday, July 09, 2013 18:04:29 Maxim Fomin wrote:On Tuesday, 9 July 2013 at 13:46:48 UTC, H. S. Teoh wrote:I'd think that having NaN != NaN would cause serious problems with retrieving any elements inserted with NaN as a key, but given how floating point values work, using them as the key for an AA is arguably completely broken to begin with as comparing floating point values for equality is generally just plain wrong. That being the case, I'd argue in favor of language consistency and just point out to anyone that runs into problems that using a floating point type as the key type of an AA is a stupid thing to do to begin with. - Jonathan M DavisOn Tue, Jul 09, 2013 at 08:05:35AM +0200, deadalnix wrote:I think it was not decided yet. From language coherency point of view NaN != NaN like in general case, from usefulness perspective you don't need several nans in AA array.On Tuesday, 9 July 2013 at 03:03:34 UTC, H. S. Teoh wrote:Not according to: http://d.puremagic.com/issues/show_bug.cgi?id=7836 So, should NaN == NaN for AA keys, or not? TMore 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 ?
Jul 09 2013
Jonathan M Davis:That being the case, I'd argue in favor of language consistencyHere I'd like D AAs act as Python dicts. This means breaking "consistency". Bye, bearophile
Jul 09 2013
On Tuesday, July 09, 2013 19:19:18 bearophile wrote:Jonathan M Davis:I'm afraid that you'll have to be more specific in terms of what you mean. But as far as I can tell, using floating point values as keys in an AA is fundamentally broken, because using == with floating point values is fundamentally broken. As such, I see no reason why it should matter that NaN is effectively unusable as an AA key. - Jonathan M DavisThat being the case, I'd argue in favor of language consistencyHere I'd like D AAs act as Python dicts. This means breaking "consistency".
Jul 09 2013
Jonathan M Davis:I'm afraid that you'll have to be more specific in terms of what you mean.Please ignore what I have said...As such, I see no reason why it should matter that NaN is effectively unusable as an AA key.OK. Bye, bearophile
Jul 09 2013
On Tuesday, 9 July 2013 at 21:12:15 UTC, Jonathan M Davis wrote:On Tuesday, July 09, 2013 19:19:18 bearophile wrote:Using floating point as keys can make sense in an ordered container actually. Just thought I'd point it out. Basically, instead of looking for specific keys, you try to position yourself between two entries. But since our AA's are hashed sets, then no, it doesn't make sense for us."Jonathan M Davis:I'm afraid that you'll have to be more specific in terms of what you mean. But as far as I can tell, using floating point values as keys in an AA is fundamentally broken, because using == with floating point values is fundamentally broken. As such, I see no reason why it should matter that NaN is effectively unusable as an AA key. - Jonathan M DavisThat being the case, I'd argue in favor of language consistencyHere I'd like D AAs act as Python dicts. This means breaking "consistency".
Jul 09 2013
On Tuesday, 9 July 2013 at 17:04:47 UTC, Jonathan M Davis wrote:On Tuesday, July 09, 2013 18:04:29 Maxim Fomin wrote:That what I meant, and you explained it much better.On Tuesday, 9 July 2013 at 13:46:48 UTC, H. S. Teoh wrote:I'd think that having NaN != NaN would cause serious problems with retrieving any elements inserted with NaN as a key, but given how floating point values work, using them as the key for an AA is arguably completely broken to begin with as comparing floating point values for equality is generally just plain wrong. That being the case, I'd argue in favor of language consistency and just point out to anyone that runs into problems that using a floating point type as the key type of an AA is a stupid thing to do to begin with. - Jonathan M DavisOn Tue, Jul 09, 2013 at 08:05:35AM +0200, deadalnix wrote:I think it was not decided yet. From language coherency point of view NaN != NaN like in general case, from usefulness perspective you don't need several nans in AA array.On Tuesday, 9 July 2013 at 03:03:34 UTC, H. S. Teoh wrote:Not according to: http://d.puremagic.com/issues/show_bug.cgi?id=7836 So, should NaN == NaN for AA keys, or not? TMore 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 ?
Jul 09 2013