diff options
author | Travis Oliphant <oliphant@enthought.com> | 2007-05-23 22:03:42 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2007-05-23 22:03:42 +0000 |
commit | d4c96cad19a58d376009f9c23aa8122dcc6d472e (patch) | |
tree | 0e9c8bebc4ba2f026932e40e07f2e5606be50a89 /numpy/lib/getlimits.py | |
parent | 8d3338b61dfe2ac2e0604ed3a1c53231e9f3d5d3 (diff) | |
download | numpy-d4c96cad19a58d376009f9c23aa8122dcc6d472e.tar.gz |
Fix up getlimits to work with Python2.3
Diffstat (limited to 'numpy/lib/getlimits.py')
-rw-r--r-- | numpy/lib/getlimits.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/numpy/lib/getlimits.py b/numpy/lib/getlimits.py index 419bce0ed..ac98babc1 100644 --- a/numpy/lib/getlimits.py +++ b/numpy/lib/getlimits.py @@ -124,10 +124,14 @@ class iinfo: """ + _min_vals = {} + _max_vals = {} + def __init__(self, type): self.dtype = N.dtype(type) self.kind = self.dtype.kind self.bits = self.dtype.itemsize * 8 + self.key = "%s%d" % (self.kind, self.bits) if not self.kind in 'iu': raise ValueError("Invalid integer data type.") @@ -136,16 +140,26 @@ class iinfo: if self.kind == 'u': return 0 else: - return -(1 << (self.bits-1)) + try: + val = iinfo._min_vals[self.key] + except KeyError: + val = int(-(1L << (self.bits-1))) + iinfo._min_vals[self.key] = val + return val min = property(min) def max(self): """Maximum value of given dtype.""" - if self.kind == 'u': - return (1 << self.bits) - 1 - else: - return (1 << (self.bits-1)) - 1 + try: + val = iinfo._max_vals[self.key] + except KeyError: + if self.kind == 'u': + val = int((1L << self.bits) - 1) + else: + val = int((1L << (self.bits-1)) - 1) + iinfo._max_vals[self.key] = val + return val max = property(max) |