• 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
NSNumberFormatter unsigned long long bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSNumberFormatter unsigned long long bug?


  • Subject: NSNumberFormatter unsigned long long bug?
  • From: Tom Bernard <email@hidden>
  • Date: Thu, 09 Oct 2008 01:08:12 -0600
  • Thread-topic: NSNumberFormatter unsigned long long bug?

NSNumberFormatter returns negative numbers for unsigned long long n such
that  (LLONG_MAX + 1) <= n <= ULLONG_MAX. Am I doing something incorrect, or
should I report this as a bug?

- (void)awakeFromNib
{
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [formatter setFormat:@"#,##0; -#,##0"];

    unsigned long long uLLongMax = ULLONG_MAX;          // debugger shows
18446744073709551615

    NSNumber *uLLongMaxNumber = [NSNumber
numberWithUnsignedLongLong:uLLongMax];                // debugger shows
18446744073709551615

    NSString *uLLongMaxString = [formatter
stringFromNumber:uLLongMaxNumber];                   // debugger shows -1

    [unsignedLongLongTextField setStringValue:uLLongMaxString];

    unsigned long long lLongMax = (unsigned long long)LLONG_MAX;    //
debugger shows 9223372036854775807

    NSNumber *lLongMaxNumber = [NSNumber
numberWithUnsignedLongLong:lLongMax];          // debugger shows
9223372036854775807

    NSString *lLongMaxString = [formatter stringFromNumber:lLongMaxNumber];
// debugger shows 9,223,372,036,854,775,807

    [unsignedLongLongTextField2 setStringValue:lLongMaxString];

    unsigned long long lLongMaxPlusOne = (unsigned long long)LLONG_MAX + 1;
// debugger shows 9223372036854775808

    NSNumber *lLongMaxPlusOneNumber = [NSNumber
numberWithUnsignedLongLong:lLongMaxPlusOne];    // debugger shows
9223372036854775808

    NSString *lLongMaxPlusOneString = [formatter
stringFromNumber:lLongMaxPlusOneNumber];       // debugger shows
-9,223,372,036,854,775,808


    [unsignedLongLongTextField3 setStringValue:lLongMaxPlusOneString];
}

Thanks in advance.

++ Tom

Tom Bernard
email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Mirror...rorriM
  • Next by Date: Re: Mirror...rorriM : Details Please
  • Previous by thread: Re: Newb Question about Delegtes and callbacks
  • Next by thread: Re: Where is close/cancel icon used in search field & Safari etc.
  • Index(es):
    • Date
    • Thread