Re: NSNumber is completely broken
Re: NSNumber is completely broken
- Subject: Re: NSNumber is completely broken
- From: Philippe Mougin <email@hidden>
- Date: Fri, 27 May 2005 13:12:43 +0200
Gerriet M. Denkmann wrote:
> It is just so that NSNumber _only_ stores some bytes and is
prepared to return
> the same bytes to you, but _not_ the encoding of these bytes.
Sometimes it returns the bytes without doing proper conversion, in
contradiction with the documentation, and thus gives wrong results,
and sometimes it does conversion (as it should).
For example:
[[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 the
documentation
> - 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. 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?
Furthermore, this is in contradiction with the purpose of NSNumber.
According to the documentation: "An NSNumber records the numeric type
it’s 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.
Best,
Philippe Mougin
http://www.fscript.org
_______________________________________________
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