[Pyobjc-dev] NSDecimalNumber to the next level
Brought to you by:
ronaldoussoren
From: Pierce T.W. I. <pi...@tw...> - 2004-03-09 17:11:52
|
I want to take NSDecimalNumber to the next level. History: 1.0. NSDecimalNumber is wrapped as identical to CFNumber, which turns out not work. 1.1 NSDecimalNumbers are passed through untransformed, you can use: dv=obj.doubleValue() to convert them to Python doubles, then: NSDecimalNumber.numberWithDouble(dv) to convert them back. This had to happen because the type information was getting lost, and the values passed back to Objective-C were plain CFNumber classes, which didn't implement NSDecimalNumber.decimalNumberByAdding_(dv), etc. 1.2? I want to work on improving this a bit, so that the NSDecimalNumber can be more or less transparent to the user so they can do something like this: Objc: + (NSDecimalNumber *) addOne: (NSDecimalNumber *) value { return [value decimalNumberByAdding: [NSDecimalNumber one]]; } Python: value1 = NSDecimalNumber.zero() value1 += 1; value2 = NSDecimalNumber.addOne(value1) if value2 = 2: print "it works!" Right now the first one doesn't work, because Python no longer knows that NSDecimalNumber can be used as a double, you have to rewrite it as: value1 = NSDecimalNumber.zero().doubleValue() value1 += 1; value2 = NSDecimalNumber.addOne( NSDecimalNumber.numberWithDouble(value1)) if value2.doubleValue() = 2: print "it works!" Which gets cumbersome quickly... I'll do the work if someone can give me a bit of an outline on what I need to do, or perhaps can point me at a class that has been custom bridged that I can crib from? Pierce |