[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re[2]: [NSDecimalNumber numberWithDouble:x]
From: |
Manuel Guesdon |
Subject: |
Re[2]: [NSDecimalNumber numberWithDouble:x] |
Date: |
Mon, 12 Jan 2004 14:52:52 +0100 (CET) |
On Mon, 12 Jan 2004 13:05:27 +0100 David Ayers <address@hidden> wrote:
>| Manuel Guesdon wrote:
>| > On 10 Jan 2004 21:00:44 -0700 Adam Fedor <address@hidden> wrote:
>| >
>| > >| On Sat, 2004-01-10 at 07:12, Manuel Guesdon wrote:
>| > >| > Hi,
>| > >| >
>| > >| > [NSDecimalNumber numberWithDouble:x] retunrs a NSDoubleNumber, not
>a NSDecimalNumber.
>| > >| > Is it correct ?
>| > >| > If yes what is the interest of NSDecimalNumber -initWithDouble: ?
>| > >| > Won't it be better to have a NSDecimalNumber -numberWithDouble: ?
>| > >| >
>| > >| > And same with for all numberWithXX: ?
>| > >| >
>| > >|
>| > >| Yes, NSDecimalNumber probably needs to override all the number methods
>| > >| (unless we wanted to put a special check in NSNumber for allocation
>from
>| > >| subclasses).
>| >
>| > Have you (or someone) a preference for the method to use ? override or
>check in numberWithXX:, like the following
>| ?
>| >
>| > + (NSNumber*) numberWithDouble: (double)value
>| > {
>| > NSNumber *theObj;
>| > if ([self isKindOfClass:decimalNumberClass])
>| > theObj=[[self alloc]initWithDouble: value];
>| > else
>| > {
>| > theObj= (NSNumber*)NSAllocateObject(doubleNumberClass, 0,
>| > NSDefaultMallocZone());
>| > theObj = [theObj initWithBytes: &value objCType: NULL];
>| > }
>| > return AUTORELEASE(theObj);
>| > }
>| >
>| > Overriding avoid additional code in NSNumber and avoid slowing it.
>| >
>| >
>| Hello,
>|
>| Acutally I agree with Adam. NSNumber should allow *any* custom
>| subclasses "to do the right thing". These aren't primiative methods.
>| So therefor these look like bugs in the NSNumber implementation to me.
>| I think all these numberWith*: methods should test:
>| if (self == [NSNumber class] || self == [applicableConcreteClass class])
>| (or rather the cached versions) before executing their current
>| implementations using the NSAllocateObject function. Otherwise it
>| should probaly just call [[self alloc] initWith*:] as you have done.
OK. Should we test against NSNumber class only or also against NSDoubleNumber,
NSShortNumber, ... for cases like:
[NSDoubleNumber numberWithDouble:xx] ? As far as I remember, NSDoubleNumber,...
are no more declared as public. So I'm
not sure this is a real problem....
BTW, as I've got another problem, what is the correct way to test if a NSNumber
is a NSDoubleNumber or a NSFloatNumber,...
before recent changes, we were able to use isKindOfClass:[NSDoubleNumber
class] ? It's interesting to know the kind of
data and use appropriate methods to keep precision
Thx.
Manuel
--
______________________________________________________________________
Manuel Guesdon - OXYMIUM <address@hidden>
14 rue Jean-Baptiste Clement - 93200 Saint-Denis - France
Tel: +33 1 4940 0999 - Fax: +33 1 4940 0998
- [NSDecimalNumber numberWithDouble:x], Manuel Guesdon, 2004/01/10
- Re[2]: [NSDecimalNumber numberWithDouble:x], Manuel Guesdon, 2004/01/11
- Re: [NSDecimalNumber numberWithDouble:x], David Ayers, 2004/01/12
- Re[2]: [NSDecimalNumber numberWithDouble:x],
Manuel Guesdon <=
- Re: [NSDecimalNumber numberWithDouble:x], David Ayers, 2004/01/12
- Re: [NSDecimalNumber numberWithDouble:x], Adam Fedor, 2004/01/12
- Re: [NSDecimalNumber numberWithDouble:x], David Ayers, 2004/01/12
- Re: [NSDecimalNumber numberWithDouble:x], Adam Fedor, 2004/01/12
- Re[2]: [NSDecimalNumber numberWithDouble:x], Manuel Guesdon, 2004/01/13
- Re[3]: [NSDecimalNumber numberWithDouble:x], Manuel Guesdon, 2004/01/31