Re: [SOLVED...but] Re: Storing NaN in NSMutableArray ?
Re: [SOLVED...but] Re: Storing NaN in NSMutableArray ?
- Subject: Re: [SOLVED...but] Re: Storing NaN in NSMutableArray ?
- From: Clark Cox <email@hidden>
- Date: Wed, 10 Mar 2004 17:08:09 -0500
On 2004/03/10, at 16:28, Glenn Andreas wrote:
>
At 10:02 PM +0100 3/10/04, Marco Scheurer wrote:
>
> On Mar 10, 2004, at 9:23 PM, Kubernan @ 10191 Tec. wrote:
>
>
>
>> Re,
>
>>
>
>> I'm sorry to say that
>
>>> [anArray addObject:[NSDecimalNumber notANumber]];
>
>>
>
>> was never called :-(
>
>> Now it works : NSLog prints NaN. But the test below :
>
>>
>
>> "if ([[anArray objectAtIndex:0] isEqualTo:[NSDecimalNumber
>
>> notANumber]])"
>
>> always returns TRUE even if the the value at the index 0 is a
>
>> NSNumber equal to +0.0 (that is not NaN value).
>
>> (same result with "isEqual" instead of "isEqualTo").
>
>>
>
>> I also tried :
>
>> "if ([[anArray objectAtIndex:0] compare:[NSDecimalNumber
>
>> notANumber]] ...)"
>
>> With no success.
>
>>
>
>> Why +0.0 is equal to NaN ??
>
>
>
> Because there's still something wrong in your code, I would say. How
>
> do you get "a NSNumber equal to +0.0" ? This is what the most
>
> elementary tests give:
>
>
>
> should ([[NSDecimalNumber notANumber] isEqual:[NSDecimalNumber
>
> notANumber]]);
>
> shouldnt ([[NSDecimalNumber notANumber] isEqual:[NSNumber
>
> numberWithFloat:0.0]]);
>
>
>
> Test Case '-[TestLab testNaN]' passed (0.001 seconds).
>
>
Even odder, NaN isn't equal to any other value, including NaN, which
>
is an easy way to test if something is NaN:
>
>
#include <stdio.h>
>
#include <math.h>
>
>
main()
>
{
>
float x = sqrt(-1.0);
>
printf("x = %g\n", x);
>
if (x == x) printf("x == x\n");
>
else printf("x != x\n");
>
}
>
>
will print out:
>
>
x = nan
>
x != x
That's true for the C concept of NaN, but not for the NSDecimalNumber
concept of NaN. I filed a bug on this over a year ago (Feb 19, 2003),
and it's currently in "Open/Analyze".
rdar://3176846
--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.