[squeak-dev] The Trunk: Balloon-nice.24.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Dec 25 21:36:03 UTC 2013


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

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

Name: Balloon-nice.24
Author: nice
Time: 25 December 2013, 10:35:43.947 pm
UUID: 97e2ed51-707d-4da1-ab4f-35add3deee5e
Ancestors: Balloon-eem.23

Change a few print:(aFloat roundTo: 0.01) into nextPutAll:(aFloat printShowingMaxDecimalPlaces: 2) or print:aFloat maxDecimalPlaces:2
Indeed, decimal fraction (1/10) (1/100) ... are not represented exactly as Float.
(1/10 - 0.1 asTrueFraction) asFloat -> -5.551115123125783e-18
So roundTo: 0.01 is an approximation which cumulates several round off errors and differs from intention (roundTo:1/100) asFloat.
Now that we print number accurately (*), this small difference causes unwanted trailing digits.
Examples:
0.3 printString-> '0.3'
(3*0.1) printString-> '0.30000000000000004'
(0.3 roundTo: 0.1) printString -> '0.30000000000000004'

* accurately = the shorter decimal fraction that would be re-interpreted unchanged

=============== Diff against Balloon-eem.23 ===============

Item was changed:
  ----- Method: BalloonEngine class>>printStat:count:string: (in category 'accessing') -----
  printStat: time count: n string: aString
  	Transcript
  		cr;
  		print: time; tab;
  		nextPutAll:' mSecs -- ';
  		print: n; tab;
  		nextPutAll:' ops -- ';
+ 		nextPutAll: ((time asFloat / (n max: 1) asFloat) printShowingMaxDecimalPlaces: 2); tab;
- 		print: ((time asFloat / (n max: 1) asFloat) roundTo: 0.01); tab;
  		nextPutAll: ' avg. mSecs/op -- ';
  		nextPutAll: aString.!



More information about the Squeak-dev mailing list