[Python-Dev] Re: [Edu-sig] Rational Division

Tim Peters tim_one@email.msn.com
Mon, 7 Feb 2000 03:03:55 -0500


[posted & mailed]

[Tim, on integer division]
> ... I'd like to take another look at what Scheme does ...

I have since been reminded that the Scheme std isn't helpful:  may return a
rational, may return a float, may return darn near anything at all -- and
may even vary depending on the specific arguments.  There's no language std
I know of more carefully crafted to ensure programs will be unportable
except for Fortran's <1/4 wink>.

> The *prime* motivation here seems to be that "7/3" not lose
> catastrophic amounts of information silently; other clear
> choices are "lose none" (rationals) and "maybe lose a little
> in a way that's very hard to explain" (floating point).

[Eric S. Raymond]
> I agree with you in preferring the "let's do rationals" answer.  Seems
> to me I recall one of the other points in the Alice presentation was that
> non-techies find floating point obscure and think of simple fractions
> as atoms.

I didn't say what I preferred <wink>.  Seriously, Guido & I corresponded
about Python's numerics when the language was being designed, and agreed
that ABC's default use of rationals didn't work out well:  "simple little"
numeric programs suffered wildly unpredictable space and time use (rationals
can "blow up" very quickly).  Have to say that hasn't been my experience in
other languages, though -- so I want to go back & see if there was something
else about ABC that conspired to produce this unhappy outcome.  Offhand, I
seem to recall that fp in ABC had a "tacked on" look & feel that made it
clumsy to get at; or maybe the docs just sucked; or maybe ...

The horrid thing about fp is that it gets *more* obscure the more you learn
about it -- until reaching "fp expert" level, which is a journey that takes
years, deliberate study, and lots of numeric scars.  REXX's decimal fp is
also an idea (it's my impression that most newbie problems with fp are due
to the "accidental complexity" introduced by using bounded binary fractions
to represent bounded decimal fractions:  this loses info for reasons that
"make no sense" in a world of decimal hand calculators and paper
arithmetic).

we-can't-win-but-we-can-choose-how-to-lose<wink>-ly y'rs  - tim