gnustep-dev
[Top][All Lists]
Advanced

[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: Sun, 11 Jan 2004 14:06:11 +0100 (CET)

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.

Manuel
-- 







reply via email to

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