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

commits at source.squeak.org commits at source.squeak.org
Wed Sep 7 17:11:19 UTC 2011

Nicolas Cellier uploaded a new version of Kernel to project The Trunk:

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

Name: Kernel-nice.614
Author: nice
Time: 7 September 2011, 7:10:52.779 pm
UUID: 8b421fd9-75f4-2e44-bef4-9bbf5cd3b57a
Ancestors: Kernel-nice.613

Let (ScaledDecimal newFromNumber: 0.0 scale: 2) print itself.

While at it, review ScaledDecimal comment and indicate that the fraction inst var can be an Integer eventually.

=============== Diff against Kernel-nice.613 ===============

Item was added:
+ ----- Method: Integer>>printTruncatedOn:showingDecimalPlaces: (in category 'printing') -----
+ printTruncatedOn: aStream showingDecimalPlaces: placesDesired
+ 	"Print a representation of the receiver on aStream in decimal notation with prescribed number of places after decimal separator.
+ 	Print as if the receiver was truncated to requested precision."
+ 	self printOn: aStream.
+ 	placesDesired > 0
+ 		ifTrue:
+ 			[aStream nextPut: $..
+ 			aStream nextPutAll: (String new: placesDesired withAll: (Character digitValue: 0))]!

Item was changed:
  Number subclass: #ScaledDecimal
  	instanceVariableNames: 'fraction scale'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Kernel-Numbers'!
+ !ScaledDecimal commentStamp: 'nice 9/7/2011 19:09' prior: 0!
- !ScaledDecimal commentStamp: '<historical>' prior: 0!
  ScaledDecimal provides a numeric representation of fixed point decimal numbers able to accurately represent decimal fractions.  It supports unbounded precision, with no limit to the number of digits before and after the decimal point.
  	ScaledDecimal complies with the ANSI protocols:
  #todo. "finish protocol list."
  Implementation Notes:
+ In order to fullfil exact arithmetic requirements, ScaledDecimal is implemented using a Fraction (or an Integer if fraction part is zero) in the fraction instance variable, and a positive Integer number of digits after the decimal point in the scale instance variable. 
- 	I implemented ScaledDecimal with the decimal fraction stored in instance variables numerator and denominator, and the number of digits after the decimal point in fractionalDigit as a positive Integer.  I implemented operations by first coercing the aurguments to fractions, doing the operations, then coercing the result to the proper numeric representation when necessary and scale.  This is because I assume the Fraction class is more likely to implement them correctly.  
+ A scaled decimal will perform arithmetic by coercing the arguments to fractions, and perform the operations with exact arithmetic.
+ Note that the denominator needs not being a power of two. If denominator has other prime factors than 2 and 5, then it cannot be printed in decimal form with a finite number of digits. Instead, the printed representation will be truncated to the number of digits prescribed in scale. But beware, the number still has hidden precision.
+ Example: 
+ | x |
+ x := 1 / 3.0s2.
+ ^{ x printString -> 'truncated print'.
+   3 * x -> 'but full precision'}
- Richard A. Harmon

More information about the Packages mailing list