• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSNumber and NaN
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSNumber and NaN


  • Subject: NSNumber and NaN
  • From: Gérard Iglesias <email@hidden>
  • Date: Fri, 18 Oct 2002 15:22:33 +0200

I found a very strange behavior around NSNumber, it seems that the
formating of -1.0.0.0 give 0.00 in place of NaN ?

Regards

GI

PS : the code

{
NSNumberFormatter * theFormatter = [[[NSNumberFormatter alloc] init]
autorelease];
NSDecimalNumber * theNan = [NSDecimalNumber notANumber];
NSNumber * the0By0 = [NSNumber numberWithFloat:0.0/0.0];
NSNumber * the1By0 = [NSNumber numberWithFloat:1.0/0.0];
NSNumber * theM1By0 = [NSNumber numberWithFloat:-1.0/0.0];

printf("format notANumber : %s\n", [[theFormatter
stringForObjectValue:theNan] lossyCString]);

printf("format 0/0 : %s\n", [[theFormatter
stringForObjectValue:the0By0] lossyCString]);
printf("format 1/0 : %s\n", [[theFormatter
stringForObjectValue:the1By0] lossyCString]);
printf("format -1/0 : %s\n", [[theFormatter
stringForObjectValue:theM1By0] lossyCString]);

printf("stringValue for 0/0 : %s\n", [[the0By0 stringValue]
lossyCString]);
printf("stringValue for 1/0 : %s\n", [[the1By0 stringValue]
lossyCString]);
printf("stringValue for -1/0 : %s\n", [[theM1By0 stringValue]
lossyCString]);

}

And the output

format notANumber : NaN
format 0/0 : NaN
format 1/0 : NaN
format -1/0 : 0.00
stringValue for 0/0 : NaN
stringValue for 1/0 : Inf
stringValue for -1/0 : -Inf
_______________________________________________
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.

  • Prev by Date: Re: NSLayoutManager vs BBEdit (Was Re: Carbon vs Cocoa arguments)
  • Next by Date: Bridging (was Re: A CFStringRef that throws EXC_BAD_ACCESS)
  • Previous by thread: Re: NSLayoutManager vs BBEdit (Was Re: Carbon vs Cocoa arguments)
  • Next by thread: Bridging (was Re: A CFStringRef that throws EXC_BAD_ACCESS)
  • Index(es):
    • Date
    • Thread