gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber Bug I can't fix


From: Richard Frith-Macdonald
Subject: Re: NSNumber Bug I can't fix
Date: Thu, 17 Feb 2011 18:08:21 +0000

On 17 Feb 2011, at 16:01, Marcus Müller wrote:

> 
>> As you can see above, asking an NSIntNumber instance for its doubleValue 
>> works properly, however, it fails at NSNumber.m:165. I don't know the 
>> reason, but I also don't understand the implications of the macros used. Can 
>> somebody elaborate? Please note that I'm on a 64-bit (amd64) system.
> 
> Thinking about it, I guess my hint was pretty bogus. I believe the real 
> problem here is the COMPARE macro which compares a double with a NaN, which 
> simply won't work:
> 
> #define COMPARE(value, other) \
> if (value < other)\
>   {\
>     return NSOrderedAscending;\
>   }\
> if (value > other)\
>   {\
>     return NSOrderedDescending;\
>   }\
> return NSOrderedSame;
> 
> If either is a nan, this will return NSOrderedSame which is, well, not 
> incorrect. However, in the context of NSNumber.m:165 it returns a wrong 
> result.
> 
> This raises the question, what should be done to - (NSComparisonResult) 
> compare: (NSNumber*)aNumber?
> Comparing a NaN with another number is undefined and might lead to 
> NSOrderedSame, but it should never lead to [2 isEqualToNumber:NaN] == YES. 
> I'm not sure how to fix this properly, but not returning NSOrderedSame in 
> this case would certainly help.

Thanks, I added a quick hack to try to fix this and put a few very simple tests 
in svn://svn.gna.org/svn/gnustep/libs/base/trunk/Tests/base/NSNumber/test01.m




reply via email to

[Prev in Thread] Current Thread [Next in Thread]