How about adding rational fraction to Python?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Feb 25 10:03:28 EST 2008


On Sun, 24 Feb 2008 23:09:39 -0800, Carl Banks wrote:

> On Feb 25, 2:04 am, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>> Carl Banks <pavlovevide... at gmail.com> writes:
>> > Try doing numerical integration sometime with rationals, and tell me
>> > how that works out.  Try calculating compound interest and storing
>> > results for 1000 customers every month, and compare the size of your
>> > database before and after.
>>
>> Usually you would round to the nearest penny before storing in the
>> database.
> 
> I throw it out there as a hypothetical, not as a real world example.
> "This is why we don't (usually) use rationals for accounting."

But since accountants (usually) round to the nearest cent, accounting is 
a *good* use-case for rationals. Decimal might be better, but floats are 
worst.

I wonder why you were doing numerical integration with rationals in the 
first place? Are you one of those ABC users (like Guido) who have learnt 
to fear rationals because ABC didn't have floats?


-- 
Steven




More information about the Python-list mailing list