File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change 4
4
"""Fraction, infinite-precision, real numbers."""
5
5
6
6
from decimal import Decimal
7
+ import functools
7
8
import math
8
9
import numbers
9
10
import operator
@@ -380,20 +381,17 @@ def reverse(b, a):
380
381
381
382
return forward , reverse
382
383
383
- def _add (a , b ):
384
- """a + b"""
384
+ def _add_sub_ (a , b , pm = int .__add__ ):
385
385
da , db = a .denominator , b .denominator
386
- return Fraction (a .numerator * db + b .numerator * da ,
386
+ return Fraction (pm ( a .numerator * db , b .numerator * da ) ,
387
387
da * db )
388
388
389
+ _add = functools .partial (_add_sub_ )
390
+ _add .__doc__ = 'a + b'
389
391
__add__ , __radd__ = _operator_fallbacks (_add , operator .add )
390
392
391
- def _sub (a , b ):
392
- """a - b"""
393
- da , db = a .denominator , b .denominator
394
- return Fraction (a .numerator * db - b .numerator * da ,
395
- da * db )
396
-
393
+ _sub = functools .partial (_add_sub_ , pm = int .__sub__ )
394
+ _sub .__doc__ = 'a - b'
397
395
__sub__ , __rsub__ = _operator_fallbacks (_sub , operator .sub )
398
396
399
397
def _mul (a , b ):
You can’t perform that action at this time.
0 commit comments