diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-07-31 20:33:49 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-07-31 20:33:49 +0000 |
commit | 0c7be2c208f3f173b3d8913e55aeb3b731fcf3f7 (patch) | |
tree | eddbd87b881affa3ce58d185f68e964cc25d5756 | |
parent | 3bbf6b2016feddcc36f0c1c73e87b4d83f928eab (diff) | |
download | numpy-0c7be2c208f3f173b3d8913e55aeb3b731fcf3f7.tar.gz |
Fix longdouble machar problem (iterations too low)
-rw-r--r-- | numpy/lib/machar.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/numpy/lib/machar.py b/numpy/lib/machar.py index e66583774..9d0e08e45 100644 --- a/numpy/lib/machar.py +++ b/numpy/lib/machar.py @@ -58,7 +58,8 @@ class MachAr(object): float_to_str - convert array float to str title - description of used floating point numbers """ - max_iter = range(1000) + max_iterN = 10000 + msg = "Did not converge after %d tries with %s" one = float_conv(1) two = one + one zero = one - one @@ -66,30 +67,30 @@ class MachAr(object): # Do we really need to do this? Aren't they 2 and 2.0? # Determine ibeta and beta a = one - for _ in max_iter: + for _ in xrange(max_iterN): a = a + a temp = a + one temp1 = temp - a if any(temp1 - one != zero): break else: - raise RuntimeError + raise RuntimeError, msg % (_, one.dtype) b = one - for _ in max_iter: + for _ in xrange(max_iterN): b = b + b temp = a + b itemp = int_conv(temp-a) if any(itemp != 0): break else: - raise RuntimeError + raise RuntimeError, msg % (_, one.dtype) ibeta = itemp beta = float_conv(ibeta) # Determine it and irnd it = -1 b = one - for _ in max_iter: + for _ in xrange(max_iterN): it = it + 1 b = b * beta temp = b + one @@ -97,18 +98,18 @@ class MachAr(object): if any(temp1 - one != zero): break else: - raise RuntimeError + raise RuntimeError, msg % (_, one.dtype) betah = beta / two a = one - for _ in max_iter: + for _ in xrange(max_iterN): a = a + a temp = a + one temp1 = temp - a if any(temp1 - one != zero): break else: - raise RuntimeError + raise RuntimeError, msg % (_, one.dtype) temp = a + betah irnd = 0 if any(temp-a != zero): @@ -125,7 +126,7 @@ class MachAr(object): for i in range(negep): a = a * betain b = a - for _ in max_iter: + for _ in xrange(max_iterN): temp = one - a if any(temp-one != zero): break @@ -136,7 +137,7 @@ class MachAr(object): raise RuntimeError, "could not determine machine tolerance " \ "for 'negep', locals() -> %s" % (locals()) else: - raise RuntimeError + raise RuntimeError, msg % (_, one.dtype) negep = -negep epsneg = a @@ -144,14 +145,14 @@ class MachAr(object): machep = - it - 3 a = b - for _ in max_iter: + for _ in xrange(max_iterN): temp = one + a if any(temp-one != zero): break a = a * beta machep = machep + 1 else: - raise RuntimeError + raise RuntimeError, msg % (_, one.dtype) eps = a # Determine ngrd @@ -166,7 +167,7 @@ class MachAr(object): z = betain t = one + eps nxres = 0 - for _ in max_iter: + for _ in xrange(max_iterN): y = z z = y*y a = z*one # Check here for underflow @@ -179,7 +180,7 @@ class MachAr(object): i = i + 1 k = k + k else: - raise RuntimeError + raise RuntimeError, msg % (_, one.dtype) if ibeta != 10: iexp = i + 1 mx = k + k @@ -192,7 +193,7 @@ class MachAr(object): mx = iz + iz - 1 # Determine minexp and xmin - for _ in max_iter: + for _ in xrange(max_iterN): xmin = y y = y * betain a = y * one @@ -207,7 +208,7 @@ class MachAr(object): else: break else: - raise RuntimeError + raise RuntimeError, msg % (_, one.dtype) minexp = -k # Determine maxexp, xmax |