[Pkg] The Trunk: Kernel-nice.400.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Feb 13 22:32:17 UTC 2010


Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.400.mcz

==================== Summary ====================

Name: Kernel-nice.400
Author: nice
Time: 13 February 2010, 11:31:43.4 pm
UUID: 20e6c813-25cb-7548-9ba7-63a83f3b5193
Ancestors: Kernel-nice.399

Change the policy for conversions to ScaledDecimal
Always honour the number of decimal places (scale) passed as argument to asScaledDecimal:

When no scale is passed, uses strictly necessary number of decimal places if the number is exact (not Float) and if a finite decimal representation exists.
Otherwise uses the default of 8 decimal places.

This makes more sense IMO than previous implementation. Integer version was screwing the user by not fulfiling the requested number of decimal places, I can't believe it was the right interpretation of the ANSI standard.... Or someone gives me a good rationale.

=============== Diff against Kernel-nice.399 ===============

Item was added:
+ ----- Method: Integer>>asScaledDecimal (in category 'converting') -----
+ asScaledDecimal
+ 	"The number of significant digits of the answer is the same as the number of decimal digits in the receiver."
+ 	^ ScaledDecimal newFromNumber: self scale: 0!

Item was added:
+ ----- Method: Fraction>>asScaledDecimal (in category 'converting') -----
+ asScaledDecimal
+ 	"Convert the receiver to a ScaledDecimal.
+ 	If there is a finite decimal representation of the receiver, then use the exact number of decimal places required.
+ 	Else, use a default number of decimals."
+ 	
+ 	| pow2 pow5 q q5 |
+ 	pow2 := denominator lowBit - 1.
+ 	q := denominator bitShift: pow2 negated.
+ 	pow5 := 0.
+ 	[q = 1]
+ 		whileFalse: [
+ 			q5 := q // 5.
+ 			(q - (5 * q5)) = 0 ifFalse: [^super asScaledDecimal].
+ 			q := q5.
+ 			pow5 := pow5 + 1].
+ 	^self asScaledDecimal: (pow2 max: pow5)!

Item was removed:
- ----- Method: Integer>>asScaledDecimal: (in category 'converting') -----
- asScaledDecimal: scaleNotUsed 
- 	"The number of significant digits of the answer is the same as the 
- 	number of decimal digits in the receiver.  The scale of the answer is 0."
- 	#Numeric.
- 	"add 200/01/19 For <integer> protocol."
- 	^ ScaledDecimal newFromNumber: self scale: 0!



More information about the Packages mailing list