1.1 --- a/lib/operator/binary.py Fri Jan 25 23:12:44 2019 +0100
1.2 +++ b/lib/operator/binary.py Fri Jan 25 23:24:33 2019 +0100
1.3 @@ -3,7 +3,8 @@
1.4 """
1.5 Operator support.
1.6
1.7 -Copyright (C) 2010, 2013, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2010, 2013, 2015, 2016, 2017,
1.9 + 2019 Paul Boddie <paul@boddie.org.uk>
1.10
1.11 This program is free software; you can redistribute it and/or modify it under
1.12 the terms of the GNU General Public License as published by the Free Software
1.13 @@ -23,7 +24,8 @@
1.14 from native import int_add, int_div, int_mod, int_mul, int_pow, int_sub, \
1.15 int_lshift, int_rshift, \
1.16 int_and, int_not, int_or, int_xor, \
1.17 - is_int
1.18 + is_int, \
1.19 + float_add, float_div, float_mul, float_pow, float_sub
1.20
1.21 # These functions defer method lookup by wrapping the attribute access in
1.22 # lambda functions. Thus, the appropriate methods are defined locally, but no
1.23 @@ -34,6 +36,8 @@
1.24 def add(a, b):
1.25 if is_int(a) and is_int(b):
1.26 return int_add(a, b)
1.27 + elif a.__class__ is float and b.__class__ is float:
1.28 + return float_add(a, b)
1.29 return binary_op(a, b, lambda a: a.__add__, lambda b: b.__radd__)
1.30
1.31 def and_(a, b):
1.32 @@ -47,6 +51,8 @@
1.33 def div(a, b):
1.34 if is_int(a) and is_int(b):
1.35 return int_div(a, b)
1.36 + elif a.__class__ is float and b.__class__ is float:
1.37 + return float_div(a, b)
1.38 return binary_op(a, b, lambda a: a.__div__, lambda b: b.__rdiv__)
1.39
1.40 def floordiv(a, b):
1.41 @@ -71,6 +77,8 @@
1.42 def mul(a, b):
1.43 if is_int(a) and is_int(b):
1.44 return int_mul(a, b)
1.45 + elif a.__class__ is float and b.__class__ is float:
1.46 + return float_mul(a, b)
1.47 return binary_op(a, b, lambda a: a.__mul__, lambda b: b.__rmul__)
1.48
1.49 def or_(a, b):
1.50 @@ -81,6 +89,8 @@
1.51 def pow(a, b):
1.52 if is_int(a) and is_int(b):
1.53 return int_pow(a, b)
1.54 + elif a.__class__ is float and b.__class__ is float:
1.55 + return float_pow(a, b)
1.56 return binary_op(a, b, lambda a: a.__pow__, lambda b: b.__rpow__)
1.57
1.58 def rshift(a, b):
1.59 @@ -91,6 +101,8 @@
1.60 def sub(a, b):
1.61 if is_int(a) and is_int(b):
1.62 return int_sub(a, b)
1.63 + elif a.__class__ is float and b.__class__ is float:
1.64 + return float_sub(a, b)
1.65 return binary_op(a, b, lambda a: a.__sub__, lambda b: b.__rsub__)
1.66
1.67 def xor(a, b):