[Python-Dev] Adding a Rational Type to Python
Michael Hudson
mwh21@cam.ac.uk
12 Mar 2001 12:03:17 +0000
"Tim Peters" <tim.one@home.com> writes:
> [Michael Hudson]
> > ...
> > Having ddd.ddd be a rational bothers me. *No* langauge does that at
> > present, do they?
>
> ABC (Python's closest predecessor) did. 6.02e23 and 1.073242e-301
> were also exact rationals. *All* numeric literals were. This
> explains why they aren't in Python, but doesn't explain exactly why:
> i.e., it didn't work well in ABC, but it's unclear whether that's
> because rationals suck, or because you got rationals even when
> 10,000 years of computer history <wink> told you that "." would get
> you something else.
Well, it seems likely that it wouldn't work in Python too, doesn't it?
Especially with 10010 years of computer history.
> > Also, writing rational numbers as decimal floats strikes me as a
> > bit loopy. Is
> >
> > 0.33333333
> >
> > 1/3 or 3333333/10000000?
>
> Neither, it's 33333333/100000000 (which is what I expect you intended for
> your 2nd choice).
Err, yes. I was feeling too lazy to count 0's.
[snip]
> OTOH, it's possible to do rational<->string conversion with an
> extended notation for "repeating decimals", e.g.
>
> str(1/3) == "0.(3)"
> eval("0.(3)") == 1/3
>
> would be possible (indeed, I've implemented it in my own rational
> classes, but not by default since identifying "the repeating part"
> in rat->string can take space proportional to the magnitude of the
> denominator).
Hmm, I wonder what the repr of rational(1,3) is...
> but-"."-is-mnemonic-for-the-"point"-in-"floating-point"-ly y'rs - tim
Quite.
Cheers,
M.
--
Slim Shady is fed up with your shit, and he's going to kill you.
-- Eminem, "Public Service Announcement 2000"