The Trunk: Kernel-dtl.548.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Kernel-dtl.548.mcz

commits-2
David T. Lewis uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-dtl.548.mcz

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

Name: Kernel-dtl.548
Author: dtl
Time: 27 February 2011, 9:51:00.787 pm
UUID: 3640676f-cde9-42ac-924b-f585949efb60
Ancestors: Kernel-cmm.547

Fix bug in Float>>printPaddedWith:To: by treating the format specifier as a string value, not as a float subject to numeric precision issues.

=============== Diff against Kernel-cmm.547 ===============

Item was changed:
  ----- Method: Float>>printPaddedWith:to: (in category 'printing') -----
  printPaddedWith: aCharacter to: aNumber
  "Answer the string containing the ASCII representation of the receiver
  padded on the left with aCharacter to be at least on aNumber
  integerPart characters and padded the right with aCharacter to be at
  least anInteger fractionPart characters."
  | aStream digits fPadding fLen iPadding iLen curLen periodIndex |
  #Numeric.
  "2000/03/04  Harmon R. Added Date and Time support"
  aStream := WriteStream on: (String new: 10).
  self printOn: aStream.
  digits := aStream contents.
  periodIndex := digits indexOf: $..
  curLen := periodIndex - 1.
  iLen := aNumber integerPart.
  curLen < iLen
  ifTrue: [iPadding := (String new: (iLen - curLen) asInteger) atAllPut: aCharacter;
  yourself]
  ifFalse: [iPadding := ''].
  curLen := digits size - periodIndex.
+ "n.b. Treat aNumber as a string format specifier rather than as a number, because
+ floating point truncation can produce incorrect results for the fraction part."
+ fLen := (aNumber asString copyAfterLast: $. )
+ ifNotEmpty: [:s | s asInteger]
+ ifEmpty: [ 0 ].
- fLen := aNumber fractionPart.
- [fLen fractionPart > 1e-6] whileTrue:
- [fLen := fLen * 10.0].
- fLen := fLen asInteger.
  curLen < fLen
  ifTrue: [fPadding := (String new: fLen - curLen) atAllPut: aCharacter;
  yourself]
  ifFalse: [fPadding := ''].
  ^ iPadding , digits , fPadding!