summaryrefslogtreecommitdiff
path: root/numpy/core/getlimits.py
diff options
context:
space:
mode:
authorJaime Fernandez <jaimefrio@google.com>2016-03-27 19:32:23 +0200
committerCharles Harris <charlesr.harris@gmail.com>2016-06-04 16:12:00 -0600
commit3071778e37112377b592b180769f0a44496dc2da (patch)
treebc4aa777fd875088e24b755758e95ab85b829961 /numpy/core/getlimits.py
parentcc51ba88af13175d4bdf9e7bf9675a88e3cb10ea (diff)
downloadnumpy-3071778e37112377b592b180769f0a44496dc2da.tar.gz
ENH: Add bits attribute to np.finfo, closes #1886
Add a bits attribute to np.finfo, document the existence of this attribute for both np.iinfo and np.finfo, plus some extra spacing around the __str__ labels to make the representation consistent for both classes.
Diffstat (limited to 'numpy/core/getlimits.py')
-rw-r--r--numpy/core/getlimits.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/numpy/core/getlimits.py b/numpy/core/getlimits.py
index 2ea9c0e11..d4025cb3b 100644
--- a/numpy/core/getlimits.py
+++ b/numpy/core/getlimits.py
@@ -30,6 +30,8 @@ class finfo(object):
Attributes
----------
+ bits : int
+ The number of bits occupied by the type.
eps : float
The smallest representable positive number such that
``1.0 + eps != 1.0``. Type of `eps` is an appropriate floating
@@ -157,6 +159,7 @@ class finfo(object):
setattr(self, word, getattr(machar, word))
for word in ['tiny', 'resolution', 'epsneg']:
setattr(self, word, getattr(machar, word).flat[0])
+ self.bits = self.dtype.itemsize * 8
self.max = machar.huge.flat[0]
self.min = -self.max
self.eps = machar.eps.flat[0]
@@ -174,12 +177,12 @@ class finfo(object):
fmt = (
'Machine parameters for %(dtype)s\n'
'---------------------------------------------------------------\n'
- 'precision=%(precision)3s resolution= %(_str_resolution)s\n'
- 'machep=%(machep)6s eps= %(_str_eps)s\n'
- 'negep =%(negep)6s epsneg= %(_str_epsneg)s\n'
- 'minexp=%(minexp)6s tiny= %(_str_tiny)s\n'
- 'maxexp=%(maxexp)6s max= %(_str_max)s\n'
- 'nexp =%(nexp)6s min= -max\n'
+ 'precision = %(precision)3s resolution = %(_str_resolution)s\n'
+ 'machep = %(machep)6s eps = %(_str_eps)s\n'
+ 'negep = %(negep)6s epsneg = %(_str_epsneg)s\n'
+ 'minexp = %(minexp)6s tiny = %(_str_tiny)s\n'
+ 'maxexp = %(maxexp)6s max = %(_str_max)s\n'
+ 'nexp = %(nexp)6s min = -max\n'
'---------------------------------------------------------------\n'
)
return fmt % self.__dict__
@@ -200,6 +203,8 @@ class iinfo(object):
Attributes
----------
+ bits : int
+ The number of bits occupied by the type.
min : int
The smallest integer expressible by the type.
max : int