[Python-Dev] Re: PEP239 (Rational Numbers) Reference Implementation
and new issues
Skip Montanaro
skip@pobox.com
Thu, 3 Oct 2002 07:30:12 -0500
Danger Will Robinson! I know next to nothing about numerical analysis. I
don't even play a numerical analyst on TV.
>> So I'm suggesting that maybe it won't get bad as quickly if you keep
>> only the significant bits :-)
Christian> Yes. And this is what a rounding to float would do for you.
Okay, we have a tension here. On the one hand, float representation
provides the convenience of bounded storage at the expense of loss of
precision. Rationals, on the other hand, have the potential to prevent loss
of precision, but at the cost of potentially unbounded storage (and greatly
increased computational cost). Is there a middle ground where you can say,
in effect, "give me rational numbers which are truncated to provide
precision no worse than N-bit floating point numbers"?
I'm sure that's stated poorly (and incorrectly), so here's an example. Pi
is an irrational number, represented in Python (at least on the platform
closest to hand) as 3.1415926535897931. Suppose I needed pi to this
precision though: 3.14159265358979323846264. Could I somehow parameterize
rational numbers to give me the required precision - that is, numerators
and/or denominators were automatically truncated to provide the desired
precision and prevent unbounded growth (space and computational)?
Skip