mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
More design notes
This commit is contained in:
parent
9c6d81f5dd
commit
9ec7bc36fe
1 changed files with 4 additions and 0 deletions
|
@ -82,6 +82,10 @@ def _binary_float_to_ratio(x):
|
||||||
_RATIONAL_FORMAT = re.compile(
|
_RATIONAL_FORMAT = re.compile(
|
||||||
r'^\s*(?P<sign>[-+]?)(?P<num>\d+)(?:/(?P<denom>\d+))?\s*$')
|
r'^\s*(?P<sign>[-+]?)(?P<num>\d+)(?:/(?P<denom>\d+))?\s*$')
|
||||||
|
|
||||||
|
# XXX Consider accepting decimal strings as input since they are exact.
|
||||||
|
# Rational("2.01") --> s="2.01" ; Rational.from_decimal(Decimal(s)) --> Rational(201, 100)"
|
||||||
|
# If you want to avoid going through the decimal module, just parse the string directly:
|
||||||
|
# s.partition('.') --> ('2', '.', '01') --> Rational(int('2'+'01'), 10**len('01')) --> Rational(201, 100)
|
||||||
|
|
||||||
class Rational(RationalAbc):
|
class Rational(RationalAbc):
|
||||||
"""This class implements rational numbers.
|
"""This class implements rational numbers.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue