[squeak-dev] Float printing significant digits

Eliot Miranda eliot.miranda at gmail.com
Fri Jun 30 18:20:16 UTC 2017


Hi All,

    an observation, a question and a suggestion.

First I hate seeing reports like this:

#55 0.33333298563957214 ratio of growth and image size at or above which a
GC will be performed post scavenge

It's far preferable to see something like

#55 0.333333 ratio of growth and image size at or above which a GC will be
performed post scavenge

but the Float printing facilities, , lose significant digits when the value
is less than zero:

(-10 to: 10) collect: [:i| | v | v := (10 raisedTo: i) asFloat / 3.
v printShowingMaxDecimalPlaces: 6] #('0' '0' '0' '0' '0' '0.000003'
'0.000033' '0.000333' '0.003333' '0.033333' '0.333333' '3.333333'
'33.333333' '333.333333' '3333.333333' '33333.333333' '333333.333333'
'3333333.333333' '33333333.333333' '333333333.333333' '3333333333.333333')

(-10 to: 10) collect: [:i| | v | v := (10 raisedTo: i) asFloat / 3.
v printShowingDecimalPlaces: 6] #('0.000000' '0.000000' '0.000000'
'0.000000' '0.000000' '0.000003' '0.000033' '0.000333' '0.003333'
'0.033333' '0.333333' '3.333333' '33.333333' '333.333333' '3333.333333'
'33333.333333' '333333.333333' '3333333.333333' '33333333.333333'
'333333333.333333' '3333333333.333333')

So the question is, are there facilities I'm missing?

My suggestion is to add something like print:showingSignificantPlaces:, e.g.


(-10 to: 10) collect: [:i| | v | v := (10 raisedTo: i) asFloat / 3.
(v >= 1 or: [v = 0 or: [v isFinite not]]) ifTrue: [v
printShowingMaxDecimalPlaces: 6] ifFalse: [v printShowingMaxDecimalPlaces:
6 - v fractionPart log rounded]]  #('0.0000000000333333'
'0.000000000333333' '0.00000000333333' '0.0000000333333' '0.000000333333'
'0.00000333333' '0.0000333333' '0.000333333' '0.00333333' '0.0333333'
'0.333333' '3.333333' '33.333333' '333.333333' '3333.333333' '33333.333333'
'333333.333333' '3333333.333333' '33333333.333333' '333333333.333333'
'3333333333.333333')

(e.g. 0.000333333333 fractionPart log =  -3.477121255153956)

If I'm not missing an obvious solution are there any objections to adding
this?
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20170630/a472a395/attachment.html>


More information about the Squeak-dev mailing list