Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > "Printing Floating-Point Numbers Quickly and Accurately"

Reply
Thread Tools

"Printing Floating-Point Numbers Quickly and Accurately"

 
 
Michael Hudson
Guest
Posts: n/a
 
      07-23-2004
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
 
Reply With Quote
 
 
 
 
Tim Peters
Guest
Posts: n/a
 
      07-24-2004
[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/ma...t/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/
 
Reply With Quote
 
 
 
 
Michael Hudson
Guest
Posts: n/a
 
      07-24-2004
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/ma...t/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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fibonacci Numbers and Lucas Numbers Andrew Tatum C++ 6 05-27-2007 12:47 AM
Reading and Writing <byte> and <char> Values from and to Disk Quickly kvnsmnsn@hotmail.com Java 7 07-06-2006 04:21 AM
Re: Numbers and more numbers... Linda A+ Certification 1 12-03-2005 12:43 AM
Re: Numbers and more numbers... Breedo A+ Certification 0 12-02-2005 12:45 AM
style sheet class and quickly changing attributes Rob HTML 6 08-05-2004 04:06 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57