"Printing Floating-Point Numbers Quickly and Accurately"

Discussion in 'Python' started by Michael Hudson, Jul 23, 2004.

  1. Does anyone (Tim?) have (ideally Python, but I can cope) code
    implementing the fixed-format algorithm from the Subject: named paper
    by Burger & Dybvig?

    Cheers,
    mwh

    --
    <Erwin> #python FAQ: How do I build X? A: Wait for twisted.X.
    -- from Twisted.Quotes
     
    Michael Hudson, Jul 23, 2004
    #1
    1. Advertising

  2. Michael Hudson

    Tim Peters Guest

    [Michael Hudson]
    > Does anyone (Tim?) have (ideally Python, but I can cope) code
    > implementing the fixed-format algorithm from the Subject: named paper
    > by Burger & Dybvig?


    I don't, and you're too young if you think anyone else might <wink>.

    The paper gives Scheme code, you know! And there's a Haskell variant here:

    http://lml.ls.fi.upm.es/~jjmoreno/manual/haskell98-library-report/numeric.html

    As the paper says at the end,

    [David] Gay ... showed that floating-point arithmetic is sufficiently
    accurate in most cases when the requested number of digits is small.
    The fixed-format printing algorithm described in this paper is useful when
    these heuristics fail.

    IOW, the point of Burger & Dybvig was to run faster than the
    algorithms in the earlier Steele & White paper, but David Gay's code
    *usually* beats everything on speed (if you don't care about speed,
    code for this task is quite simple; if you do care about speed, it's
    mind-numbingly complicated), so there's little incentive to implement
    this algorithm. Gay's code is written in C, & available from Netlib:

    http://www.netlib.org/fp/
     
    Tim Peters, Jul 24, 2004
    #2
    1. Advertising

  3. Tim Peters <> writes:

    > [Michael Hudson]
    > > Does anyone (Tim?) have (ideally Python, but I can cope) code
    > > implementing the fixed-format algorithm from the Subject: named paper
    > > by Burger & Dybvig?

    >
    > I don't, and you're too young if you think anyone else might <wink>.
    >
    > The paper gives Scheme code, you know!


    Not for the fixed format algorithm it doesn't. The paper says:

    The rational arithmetic used in fixed-format printing can wbe
    converted into high-precision integer arithmetic by introducing a
    common denominator as before. Because there are several more cases
    to consider, however, the resulting code is lengthy and has
    therefore been omitted from this paper.

    I was hoping someone else had considered all the cases for me :)

    I've already translated the free format code from the paper into
    Python, unfortunately it's not what I actually need...

    > And there's a Haskell variant here:
    >
    > http://lml.ls.fi.upm.es/~jjmoreno/manual/haskell98-library-report/numeric.html


    That's the free format algorithm again, unless I've gone blind.

    > As the paper says at the end,
    >
    > [David] Gay ... showed that floating-point arithmetic is sufficiently
    > accurate in most cases when the requested number of digits is small.
    > The fixed-format printing algorithm described in this paper is useful when
    > these heuristics fail.
    >
    > IOW, the point of Burger & Dybvig was to run faster than the
    > algorithms in the earlier Steele & White paper, but David Gay's code
    > *usually* beats everything on speed (if you don't care about speed,
    > code for this task is quite simple; if you do care about speed, it's
    > mind-numbingly complicated), so there's little incentive to implement
    > this algorithm.


    I'm probably suffering from an attack of perfectionism. Burger &
    Dubvig's algorithm is so neat!

    > Gay's code is written in C, & available from Netlib:
    >
    > http://www.netlib.org/fp/


    Now *that* code is over-the-top, even for me :)

    Cheers,
    mwh

    --
    . <- the point your article -> .
    |------------------------- a long way ------------------------|
    -- Christophe Rhodes, ucam.chat
     
    Michael Hudson, Jul 24, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page