diff options
Diffstat (limited to 'numpy/lib/machar.py')
-rw-r--r-- | numpy/lib/machar.py | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/numpy/lib/machar.py b/numpy/lib/machar.py index 443fef83b..e66583774 100644 --- a/numpy/lib/machar.py +++ b/numpy/lib/machar.py @@ -58,6 +58,7 @@ class MachAr(object): float_to_str - convert array float to str title - description of used floating point numbers """ + max_iter = range(1000) one = float_conv(1) two = one + one zero = one - one @@ -65,41 +66,49 @@ class MachAr(object): # Do we really need to do this? Aren't they 2 and 2.0? # Determine ibeta and beta a = one - while 1: + for _ in max_iter: a = a + a temp = a + one temp1 = temp - a if any(temp1 - one != zero): break + else: + raise RuntimeError b = one - while 1: + for _ in max_iter: b = b + b temp = a + b itemp = int_conv(temp-a) if any(itemp != 0): break + else: + raise RuntimeError ibeta = itemp beta = float_conv(ibeta) # Determine it and irnd it = -1 b = one - while 1: + for _ in max_iter: it = it + 1 b = b * beta temp = b + one temp1 = temp - b if any(temp1 - one != zero): break + else: + raise RuntimeError betah = beta / two a = one - while 1: + for _ in max_iter: a = a + a temp = a + one temp1 = temp - a if any(temp1 - one != zero): break + else: + raise RuntimeError temp = a + betah irnd = 0 if any(temp-a != zero): @@ -116,7 +125,7 @@ class MachAr(object): for i in range(negep): a = a * betain b = a - while 1: + for _ in max_iter: temp = one - a if any(temp-one != zero): break @@ -126,6 +135,8 @@ class MachAr(object): if negep < 0: raise RuntimeError, "could not determine machine tolerance " \ "for 'negep', locals() -> %s" % (locals()) + else: + raise RuntimeError negep = -negep epsneg = a @@ -133,12 +144,14 @@ class MachAr(object): machep = - it - 3 a = b - while 1: + for _ in max_iter: temp = one + a if any(temp-one != zero): break a = a * beta machep = machep + 1 + else: + raise RuntimeError eps = a # Determine ngrd @@ -153,7 +166,7 @@ class MachAr(object): z = betain t = one + eps nxres = 0 - while 1: + for _ in max_iter: y = z z = y*y a = z*one # Check here for underflow @@ -165,6 +178,8 @@ class MachAr(object): break i = i + 1 k = k + k + else: + raise RuntimeError if ibeta != 10: iexp = i + 1 mx = k + k @@ -177,7 +192,7 @@ class MachAr(object): mx = iz + iz - 1 # Determine minexp and xmin - while 1: + for _ in max_iter: xmin = y y = y * betain a = y * one @@ -191,6 +206,8 @@ class MachAr(object): break else: break + else: + raise RuntimeError minexp = -k # Determine maxexp, xmax |