[squeak-dev] The Inbox: Kernel-nice.651.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Nov 3 22:13:19 UTC 2011


Nicolas Cellier uploaded a new version of Kernel to project The Inbox:
http://source.squeak.org/inbox/Kernel-nice.651.mcz

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

Name: Kernel-nice.651
Author: nice
Time: 3 November 2011, 11:12:46.086 pm
UUID: c8b1e674-7598-479c-b705-83dca79959f2
Ancestors: Kernel-eem.648

Print Float with the minimal number of decimal digits that describe it unambiguously.
This way, every two different Float will have a different printed representation.
More over, every Float can be reconstructed from its printed representation.

I've made this change in Pharo.
Now I'd really like to get this in Squeak too.

These are obscuring our data:
	0.1 successor printString = 0.1 printString.
	1.0e-100 printString = '9.99999999999999e-101'.

If we want some representation with limited number of digits, then let's ask for it.
But a default behaviour returning so many digits without bijection is just useless.

Maybe some won't like
	Float nan printString = 'Float nan'.
But that's a detail we can eventually change back.

The essential is to use absPrintExactlyOn:base:
Side note: this is really a bad name, because it prints the shortest base-representation, not the exact one.
Anyway, it can only print the exact one in even bases.
For example, the exact representation of 0.1 in base 10 is 0.1 asFraction asScaledDecimal 0.1000000000000000055511151231257827021181583404541015625s55

=============== Diff against Kernel-eem.648 ===============

Item was changed:
  ----- Method: Float>>printOn:base: (in category 'printing') -----
  printOn: aStream base: base
+ 	"Print the receiver with the minimal number of digits that describe it unambiguously.
+ 	This way, every two different Float will have a different printed representation.
+ 	More over, every Float can be reconstructed from its printed representation." 
- 	"Handle sign, zero, and NaNs; all other values passed to absPrintOn:base:" 
  
+ 	self storeOn: aStream base: base!
- 	self isNaN ifTrue: [aStream nextPutAll: 'NaN'. ^ self]. "check for NaN before sign"
- 	self > 0.0
- 		ifTrue: [self absPrintOn: aStream base: base]
- 		ifFalse:
- 			[self sign = -1
- 				ifTrue: [aStream nextPutAll: '-'].
- 			self = 0.0
- 				ifTrue: [aStream nextPutAll: '0.0'. ^ self]
- 				ifFalse: [self negated absPrintOn: aStream base: base]]!




More information about the Squeak-dev mailing list