|[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]|
Date: Fri, 27 May 2005 13:12:43 +0200 From: Philippe Mougin <email@hidden> Subject: Re: NSNumber is completely broken
[[NSNumber numberWithUnsignedChar:200] doubleValue] returns -56 (which is wrong, it should return 200).
However, [[NSNumber numberWithInt:200] doubleValue] returns 200 (which implies it converts the bytes from the integer to floating point representation and provides the expected result).
So there is the very easy rule (which really should be in thedocumentation- I was fooled by NSNumber myself): if you use NSNumber you must someplace else remember the _type_ of the data stored in NSNumber.
In most cases, you can't apply this rule, because you are not the creator of the NSNumber you want to use.
In these cases NSNumber (as it is right now) is quite useless.
For instance, how do you use an NSNumber that is handed to you by Core Data or one of the numerous Cocoa APIs that provides you with NSNumber instances?
Yes - I just checked. And I would really like an NSNumber which follows this documentation.
Furthermore, this is in contradiction with the purpose of NSNumber. According to the documentation: "An NSNumber records the numeric type its created with, and uses the C rules for numeric conversion when comparing NSNumbers of different numeric types and when returning values as C numeric types."
NSNumber is really broken.
You are right - NSNumber is a sad mess.
_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
Visit the Apple Store online or at retail locations.
Copyright © 2011 Apple Inc. All rights reserved.