Re: [Pyobjc-dev] NSDecimalNumber to the next level
Brought to you by:
ronaldoussoren
From: Pierce T.W. I. <pi...@tw...> - 2004-03-09 18:39:07
|
>> 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. > > The type info should not get lost, NSDecimalNumber and NSDecimal (the > C type backing the NSDecimalNumber class) should work correctly as > numbers, including save coercions. I explicitly disabled implicit > coercion from NSDecimal{Number,} to and from float because you might > loose precision that way. > > If this doesn't work you found a bug that should be fixed. Call me crazy, but I'd like to get this code to work: import objc import Foundation print Foundation.NSDecimalNumber.zero().decimalNumberByAdding_(Foundation.NSDe cimalNumber.zero()) print Foundation.NSDecimalNumber.zero().decimalNumberByAdding_(1.0) That's what I would like to be able to do. Perhaps its not possible though, I dunno. Is the bridge able to detect when a method is expecting an NSDecimalNumber * for a parameter? Pierce |