Re: NSNumber : method to return pointer to represented value
Re: NSNumber : method to return pointer to represented value
- Subject: Re: NSNumber : method to return pointer to represented value
- From: Ken Thomases <email@hidden>
- Date: Sun, 23 Feb 2014 08:04:01 -0600
On Feb 22, 2014, at 1:28 PM, email@hidden wrote:
> On 22 Feb 2014, at 15:32, Ken Thomases <email@hidden> wrote:
>>>
>>
>> NSDecimalNumber can represent values that are outside of the range of doubles. So, _some_ NSDecimalNumber instances _may_ return "d" for double, but others definitely won't.
>>
> I don’t think so.
> It is possible that this behaviour could change and yes my type hinting system would then break.
> However, the current behaviour to me seems entirely self consistent.
>
> The NSDecimalNumber header says:
> - (const char *)objCType NS_RETURNS_INNER_POINTER;
> // return 'd' for double
Actually, this is much, much worse. If the representation provided by -getValue: is a double and a double can't represent all of the different values of an NSDecimalNumber, then two unequal number objects would have equal representations. That will play havoc with dictionary lookups.
NSDecimalNumber* dn1 = [NSDecimalNumber decimalNumberWithMantissa:ULLONG_MAX exponent:0 isNegative:NO];
NSDecimalNumber* dn2 = [dn1 decimalNumberBySubtracting:[NSDecimalNumber one]];
double d1, d2;
[dn1 getValue:&d1];
[dn2 getValue:&d2];
assert(![dn1 isEqual:dn2]); // passes
assert(d1 != d2); // fails
Regards,
Ken
_______________________________________________
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