This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2008年07月04日 19:36 by rhettinger, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| from_any.diff | rhettinger, 2008年07月04日 19:36 | Patch to fractions.py | ||
| Messages (2) | |||
|---|---|---|---|
| msg69264 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2008年07月04日 19:36 | |
After exercising the fractions module, I've found it problematic that there isn't a unified constructor to handle mixed data input types. For example, when updating the accurate summation recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393090 to show how it could be done with rational arithmetic. Handling mixed-type inputs required writing a factory function: def makefrac(x): if isinstance(x, Decimal): return Fraction.from_decimal(x) if isinstance(x, float): return Fraction.from_float(x) return Fraction(x) That function supported a clean version of the recipe: def frsum(iterable): return float(sum(map(makefrac, iterable))) It would have been much better if that functionality were built into the class definition. See attached patch. |
|||
| msg69505 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2008年07月10日 14:36 | |
Adopted the solution used by functions in the math module. Functions that accept floats also accept integral inputs. This improves usability in face of mixed float/int data or decimal/int data. See r64846. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:36 | admin | set | github: 47535 |
| 2008年07月10日 14:36:31 | rhettinger | set | status: open -> closed resolution: fixed messages: + msg69505 |
| 2008年07月04日 19:36:26 | rhettinger | create | |