[Python-checkins] r60271 - python/trunk/Lib/rational.py

raymond.hettinger python-checkins at python.org
Fri Jan 25 01:33:46 CET 2008


Author: raymond.hettinger
Date: Fri Jan 25 01:33:45 2008
New Revision: 60271

Modified:
   python/trunk/Lib/rational.py
Log:
Mark todos and review comments.

Modified: python/trunk/Lib/rational.py
==============================================================================
--- python/trunk/Lib/rational.py	(original)
+++ python/trunk/Lib/rational.py	Fri Jan 25 01:33:45 2008
@@ -40,6 +40,8 @@
     >>> _binary_float_to_ratio(-.25)
     (-1, 4)
     """
+    # XXX Consider moving this to to floatobject.c
+    # with a name like float.as_intger_ratio()
 
     if x == 0:
         return 0, 1
@@ -219,6 +221,16 @@
         else:
             return '%s/%s' % (self.numerator, self.denominator)
 
+    """ XXX This section needs a lot more commentary
+
+    * Explain the typical sequence of checks, calls, and fallbacks.
+    * Explain the subtle reasons why this logic was needed.
+    * It is not clear how common cases are handled (for example, how
+      does the ratio of two huge integers get converted to a float
+      without overflowing the long-->float conversion.
+
+    """
+
     def _operator_fallbacks(monomorphic_operator, fallback_operator):
         """Generates forward and reverse operators given a purely-rational
         operator and a function from the operator module.
@@ -419,6 +431,7 @@
         float must have the same hash as that float.
 
         """
+        # XXX since this method is expensive, consider caching the result
         if self.denominator == 1:
             # Get integers right.
             return hash(self.numerator)


More information about the Python-checkins mailing list