diff options
author | Travis Oliphant <oliphant@enthought.com> | 2007-05-23 19:30:18 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2007-05-23 19:30:18 +0000 |
commit | 8f0db8c41c17af95900c0cdfe71aa6916b5094c3 (patch) | |
tree | 4e7bab238d01d6299ceac106968d20998fd9073c /numpy/lib/getlimits.py | |
parent | 519e621cce49d0f6bf3f76ffbe84537ec81b532a (diff) | |
download | numpy-8f0db8c41c17af95900c0cdfe71aa6916b5094c3.tar.gz |
Expose numpy.iinfo and re-implement so it supports big-endian as well.
Diffstat (limited to 'numpy/lib/getlimits.py')
-rw-r--r-- | numpy/lib/getlimits.py | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/numpy/lib/getlimits.py b/numpy/lib/getlimits.py index a0a2a94ca..419bce0ed 100644 --- a/numpy/lib/getlimits.py +++ b/numpy/lib/getlimits.py @@ -1,7 +1,7 @@ """ Machine limits for Float32 and Float64 and (long double) if available... """ -__all__ = ['finfo'] +__all__ = ['finfo','iinfo'] from machar import MachAr import numpy.core.numeric as numeric @@ -124,39 +124,29 @@ class iinfo: """ - # Should be using dtypes as keys, but hash-function isn't yet implemented - _min_values = {'int8': -2**7, - 'int16': -2**15, - 'int32': -2**31, - 'int64': -2**63, - 'uint8': 0, - 'uint16': 0, - 'uint32': 0, - 'uint64': 0} - - _max_values = {'int8': 2**7 - 1, - 'int16': 2**15 - 1, - 'int32': 2**31 - 1, - 'int64': 2**63 - 1, - 'uint8': 2**8 - 1, - 'uint16': 2**16 - 1, - 'uint32': 2**32 - 1, - 'uint64': 2**64 - 1} - def __init__(self, type): - self.dtype = str(N.dtype(type)) - if not (self.dtype in self._min_values and \ - self.dtype in self._max_values): + self.dtype = N.dtype(type) + self.kind = self.dtype.kind + self.bits = self.dtype.itemsize * 8 + if not self.kind in 'iu': raise ValueError("Invalid integer data type.") def min(self): """Minimum value of given dtype.""" - return self._min_values[self.dtype] + if self.kind == 'u': + return 0 + else: + return -(1 << (self.bits-1)) + min = property(min) def max(self): """Maximum value of given dtype.""" - return self._max_values[self.dtype] + if self.kind == 'u': + return (1 << self.bits) - 1 + else: + return (1 << (self.bits-1)) - 1 + max = property(max) if __name__ == '__main__': |