[issue8947] Provide as_integer_ratio() method to Decimal

Alexander Belopolsky report at bugs.python.org
Sat Jun 12 05:24:52 CEST 2010

Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

Nice implementation.  I wonder if the /5 loop can be eliminated by noting that /5 is *2 followed by decimal shift. (Probably not without fast decimal arithmetics.)

A few documentation nits:

1. In Decimal methods there is no consistency in referring to self.  I see  "given Decimal", "the number", and "the argument" in three entries around as_integer_ratio().

2. Is there a reason that docstring is more detailed than manual entry?  I think the manual should describe exceptions.

3. Is there a reason to use different language for float.as_integer_ratio() and Decimal.as_integer_ratio()?

I know, ""A foolish consistency is the hobgoblin of little minds..." - feel free to ignore my observations.

A tiny code nit: to me it would be clearer to start with d2 = d5 = -self._exp after the "# Find d2, d5 ..." comment.  For a moment I was puzzled why you promise d2 and d5, but then process d5 only.

Also, by the time of the "if not self" check, special case has been eliminated, so you can simply check self._int == 0.


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list