Using fractions instead of floats
Raymond L. Buvel
levub137 at wi.rr.com
Wed Oct 3 15:12:20 CEST 2007
Neil Cerutti wrote:
>> Another guess could be that real numbers being closed under the
>> four arithmetic operations, there is no danger to accidentally
>> step into complex numbers. OTOH floats and rationals are two
>> (conflicting) ways of extending integers.
> You would have to adopt a few simple conversion rules, a la
> Scheme. Inexact numbers are contagious, for example. It was
> pretty shocking for a Scheme programmer to see the gmpy package
> break that rule. ;)
There is another package that supports rationals.
One of the reasons I created this package is that I didn't like
implicit conversion of inexact numbers to exact numbers. Instead
clnum either raises an exception (with Python floats and complex)
or converts the rational to a compatible inexact type (with mpf
Other reasons for creating this package are gmpy doesn't support
complex numbers or the functions in the math and cmath modules.
However, gmpy does have many capabilities that are not in clnum so
you need to choose based on the type of problem you want to solve.
More information about the Python-list