Re: NSNumber is completely broken
Re: NSNumber is completely broken
- Subject: Re: NSNumber is completely broken
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Fri, 27 May 2005 20:03:28 +0200
Date: Fri, 27 May 2005 13:12:43 +0200
From: Philippe Mougin <email@hidden>
Subject: Re: NSNumber is completely broken
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).
Well, NSNumber takes its input, sign-extends it to 32 bit if shorter
and stores it as "i".
You are right: to sign-extend an unsigned char is hard to justify.
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.
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?
Assume they represent a signed int and hope that this turns out to be
true.
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."
Yes - I just checked. And I would really like an NSNumber which follows
this documentation.
NSNumber is really broken.
You are right - NSNumber is a sad mess.
Kind regards,
Gerriet.
_______________________________________________
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