http://www.rubycentral.com/book/ref_c_array.html#slice_oh

Paul Prescod paulp at ActiveState.com
Fri Apr 20 08:24:07 EDT 2001


"M.-A. Lemburg" wrote:
> 
>...
> 
> Well, the above bullet was meant to show that typing 1.1 doesn't
> result in Python generating a true representation of that value,
> but instead:
> 
> >>> from mx.Number import *
> >>> Float(1.1)
> 1.10000000000000008882e+0
> >>> Rational(1.1)
> 2476979795053773/2251799813685248
> 
> This is a common misunderstanding and the reason for Moshe proposing
> to have 1.1 produce a Rational(11, 10) instead of a float.

Right, this is why creating rationals from floats will usually be a bad
idea. Perhaps creating a rational from a float should require an extra
step that shows that you understand that this is not the "normal" way to
create a rational. i.e. RationalFromFloat(1.1) or even
RationalFromInexact(1.1)

Despite these nits, I think that mx.Number is very cool!

> Note that GMP is blazingly fast, so the performance hit is
> probably negligable (haven't done any real tests yet, since
> mx.Number is not up to it yet and still provides a lot of
> air for performance improvements).

But no matter how fast a particular implementation is, my understanding
is that rational numbers are slower than floats at a deeply algorithmic
level. Correct?

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list