The Trunk: Kernel-bf.710.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-bf.710.mcz

commits-2
Bert Freudenberg uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-bf.710.mcz

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

Name: Kernel-bf.710
Author: bf
Time: 4 September 2012, 1:54:08.616 pm
UUID: 772d3014-9910-4231-bee1-36d35938014d
Ancestors: Kernel-ul.709

For printing Time, do not use Floats. E.g., '6:27:08.649' asTime was printed as '6:27:08.649000000000001 am' due to converting to floating point for printing, when the representation itself uses precise numbers (nanoseconds). This fix introduces Integer>>printOn:asFixedPoint: which might not be the best idea; if some other dialect has an existing method that does something similar we should use that selector.

=============== Diff against Kernel-ul.709 ===============

Item was added:
+ ----- Method: Integer>>printOn:asFixedPoint: (in category 'printing') -----
+ printOn: aStream asFixedPoint: base
+ "assume I am a fixedpoint decimal scaled by base"
+ "String streamContents: [:s | 1234 printOn: s asFixedPoint: 1000]"
+
+ | b n |
+ self < 0 ifTrue: [aStream nextPut: $-.
+ ^self negated printOn: aStream asFixedPoint: base].
+ b := base.
+ n := self.
+ [aStream print: n // b.
+ (n := n \\ b) = 0] whileFalse: [
+ b = base ifTrue: [aStream nextPut: $.].
+ b := b // 10].
+ !

Item was changed:
  ----- Method: Time>>print24:showSeconds:on: (in category 'printing') -----
  print24: hr24 showSeconds: showSeconds on: aStream
  "Format is 'hh:mm:ss' or 'h:mm:ss am'  or, if showSeconds is false, 'hh:mm' or 'h:mm am'"
 
  | h m s |
  h := self hour. m := self minute. s := self second.
  hr24
  ifTrue:
  [ h < 10 ifTrue: [ aStream nextPutAll: '0' ].
  h printOn: aStream ]
  ifFalse:
  [ h > 12
  ifTrue: [h - 12 printOn: aStream]
  ifFalse:
  [h < 1
  ifTrue: [ 12 printOn: aStream ]
  ifFalse: [ h printOn: aStream ]]].
 
  aStream nextPutAll: (m < 10 ifTrue: [':0'] ifFalse: [':']).
  m printOn: aStream.
 
  showSeconds ifTrue:
  [ aStream nextPutAll: (s < 10 ifTrue: [':0'] ifFalse: [':']).
  self nanoSecond = 0
  ifTrue: [s asInteger printOn: aStream]
+ ifFalse: [s asInteger * NanosInSecond + self nanoSecond asInteger
+ printOn: aStream asFixedPoint: NanosInSecond]].
- ifFalse: [(s + (self nanoSecond / NanosInSecond) asFloat) printOn: aStream]].
 
  hr24 ifFalse:
  [ aStream nextPutAll: (h < 12 ifTrue: [' am'] ifFalse: [' pm']) ].
  !