gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NSDecimalNumber numberWithDouble:x]


From: David Ayers
Subject: Re: [NSDecimalNumber numberWithDouble:x]
Date: Mon, 12 Jan 2004 13:05:27 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031210

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.

But I haven't dug into it yet...

Cheers,
David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]