1.1 --- a/micropython/common.py Sun Jun 13 02:24:35 2010 +0200
1.2 +++ b/micropython/common.py Mon Jun 14 01:46:42 2010 +0200
1.3 @@ -111,6 +111,51 @@
1.4
1.5 pass
1.6
1.7 +# Special representations.
1.8 +
1.9 +class AtLeast:
1.10 +
1.11 + "A special representation for numbers of a given value or greater."
1.12 +
1.13 + def __init__(self, count):
1.14 + self.count = count
1.15 +
1.16 + def __eq__(self, other):
1.17 + return 0
1.18 +
1.19 + __lt__ = __le__ = __eq__
1.20 +
1.21 + def __ne__(self, other):
1.22 + return 1
1.23 +
1.24 + def __gt__(self, other):
1.25 + if isinstance(other, AtLeast):
1.26 + return 0
1.27 + else:
1.28 + return self.count > other
1.29 +
1.30 + def __ge__(self, other):
1.31 + if isinstance(other, AtLeast):
1.32 + return 0
1.33 + else:
1.34 + return self.count >= other
1.35 +
1.36 + def __iadd__(self, other):
1.37 + if isinstance(other, AtLeast):
1.38 + self.count += other.count
1.39 + else:
1.40 + self.count += other
1.41 + return self
1.42 +
1.43 + def __radd__(self, other):
1.44 + if isinstance(other, AtLeast):
1.45 + return AtLeast(self.count + other.count)
1.46 + else:
1.47 + return AtLeast(self.count + other)
1.48 +
1.49 + def __repr__(self):
1.50 + return "AtLeast(%r)" % self.count
1.51 +
1.52 # Useful data.
1.53
1.54 comparison_methods = {