Movatterモバイル変換
[0]ホーム
[Python-Dev] Re: PEP239 (Rational Numbers) Reference Implementation and new issues
Tim Peterstim.one@comcast.net
Tue, 08 Oct 2002 22:18:46 -0400
[Guido, on 3/5r]> I'd like at least one of those return '0.6' or '0.6r'.[Oren Tirosh]> Why should any of them go through a potetially lossy transformation?0.6r is exact, although it's hard to know whether Guido was hoping topreserve that or not.> If you need to approximate a ratio as a finite decimal fraction it should> be explicit: str(float(r)).> I think it will also make a good visual cue to always use> rational notation for rationals and decimal fractions for floats.The trailing 'r' *is* rational notation, and stuff like this probably isn'ta good idea for str():> #e6.02e-45301/50000000000000000000000000000000000000000000000>6.02e-45r would be clearer to virtually anyone.> (+ 312 (/ 1 3))937/3>would likely be clearer to virtually anyone as 312+1/3r too.But most of all, I agree that if you're working with rationals, you don'twant to lose information silently, not even in a "pleasant" string.> The result of repr() should eval() back to exactly the same object. The> result of str() should be the 'pretty' representation because this is the> form displayed by print statements and %s formatting. I find> '2/3' prettier than '0.666666666667'2/3r works for both for me. 0.666...7 doesn't work for me at all as astringification of a rational (if I want to approximate, I'll ask for anapproximation).
[8]ページ先頭