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: Glenn Andreas <email@hidden>
- Date: Wed, 10 Mar 2004 15:28:36 -0600
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
--
Glenn Andreas email@hidden
mondo blobbo, Cythera, Theldrow, oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
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.