A rational proposal
Nick Coghlan
ncoghlan at iinet.net.au
Wed Dec 22 08:25:06 EST 2004
Mike Meyer wrote:
> Well, you want to be able to add floats to rationals. The results
> shouldn't be rational, for much the same reason as you don't want to
> convert floats to rationals directly. I figure the only choice that
> leaves is that the result be a float. That and float(rational) should
> be the only times that a rational gets turned into a float.
>
> Are you suggestiong that float(rational) should be a string, with the
> number of degrees of precesion set by something like the Context type
> in Decimal?
Actually, I was misremembering how Decimal worked - it follows the rule you suggest:
float() + Decimal() fails with a TypeError
float() + float(Decimal()) works fine
And I believe Decimal's __float__ operation is a 'best effort' kind of thing, so
I have no problem with Rationals working the same way.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list