in reply to Display floating point numbers in compact, fixed-width format

I'm confused by this transition in the output from your test program

... 0.05555555555 (+0.055556) -0.05555555555 (-0.055556) 0.5555555555 ( +0.556) -0.5555555555 ( -0.556) ...

I realise that the answer could just be, "Because that's what I want!", but why suddenly start throwing away precision in favour of whitespace? And why at this point?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.

Replies are listed 'Best First'.
Re^2: Display floating point numbers in compact, fixed-width format (thanks)
by tye (Sage) on Sep 24, 2003 at 17:12 UTC

    The motivation is:

    Numbers of similar magnitude line up their decimal points

    But it appears I have an off-by-one error for when to transition to that other format. So I've changed

    -2 => '+0.000000',
    to
    -1 => '+0.000000',
    and added some more test cases (which found another bug that I've fixed -- stripping trailing '0's when I shouldn't). Thanks for catching that.

    At which points to change format are partially a matter of taste. The first three formats have very little room for matters of taste:

    -100 => '+1.0e-999', -10 => '+1.00e-99', -5 => '+1.000e-9',
    (the most likely change would be to change "-5", probably to something a bit closer to zero).

    The last three have only slightly more room:

    +9 => '+1.000e+9', +99 => '+1.000e99', +99999 => '+1.00e999',
    but the middle ground leaves lots of room for trade-offs. In particular, I wanted small integers to line up nicely (I chose -9999..9999 for my definition of "small") and I wanted a +0.0 format so that we can tell near-integers from non-integers for as long as possible. The +0.000000 and +0 formats allow us to delay going to 'e' format for as long as possible.

    Finally, add in a desire for fewer formats so that numbers are more likely to line up at their (perhaps implied) decimal points, and I'm stuck with what I used above. (:

                    - tye