1.1 --- a/lib/operator/comparison.py Fri Jan 25 23:12:44 2019 +0100
1.2 +++ b/lib/operator/comparison.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 @@ -20,7 +21,8 @@
1.14 """
1.15
1.16 from operator.core import binary_op
1.17 -from native import int_eq, int_ge, int_gt, int_le, int_lt, int_ne, is_int
1.18 +from native import int_eq, int_ge, int_gt, int_le, int_lt, int_ne, is_int, \
1.19 + float_eq, float_ge, float_gt, float_le, float_lt, float_ne
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 @@ -31,31 +33,43 @@
1.24 def eq(a, b):
1.25 if is_int(a) and is_int(b):
1.26 return int_eq(a, b)
1.27 + elif a.__class__ is float and b.__class__ is float:
1.28 + return float_eq(a, b)
1.29 return binary_op(a, b, lambda a: a.__eq__, lambda b: b.__eq__, False)
1.30
1.31 def ge(a, b):
1.32 if is_int(a) and is_int(b):
1.33 return int_ge(a, b)
1.34 + elif a.__class__ is float and b.__class__ is float:
1.35 + return float_ge(a, b)
1.36 return binary_op(a, b, lambda a: a.__ge__, lambda b: b.__le__)
1.37
1.38 def gt(a, b):
1.39 if is_int(a) and is_int(b):
1.40 return int_gt(a, b)
1.41 + elif a.__class__ is float and b.__class__ is float:
1.42 + return float_gt(a, b)
1.43 return binary_op(a, b, lambda a: a.__gt__, lambda b: b.__lt__)
1.44
1.45 def le(a, b):
1.46 if is_int(a) and is_int(b):
1.47 return int_le(a, b)
1.48 + elif a.__class__ is float and b.__class__ is float:
1.49 + return float_le(a, b)
1.50 return binary_op(a, b, lambda a: a.__le__, lambda b: b.__ge__)
1.51
1.52 def lt(a, b):
1.53 if is_int(a) and is_int(b):
1.54 return int_lt(a, b)
1.55 + elif a.__class__ is float and b.__class__ is float:
1.56 + return float_lt(a, b)
1.57 return binary_op(a, b, lambda a: a.__lt__, lambda b: b.__gt__)
1.58
1.59 def ne(a, b):
1.60 if is_int(a) and is_int(b):
1.61 return int_ne(a, b)
1.62 + elif a.__class__ is float and b.__class__ is float:
1.63 + return float_ne(a, b)
1.64 return binary_op(a, b, lambda a: a.__ne__, lambda b: b.__ne__, True)
1.65
1.66 # vim: tabstop=4 expandtab shiftwidth=4