This is an automatically generated file.
Part 1
Part 2
# =============================================
# Test for extra precison.
# =============================================
def test_for_extra_precise_subepressions():
"""Print messages if wider intermediate values detected.
"""
Part 3
# (4/3 -1) - 1/4 = 1/12 with rounding error in values bigger than 1.
# 3 * rounded value - 1/4 should be some rounding error in 1+.
# z2 should be an ulp of 1+, unless the computation of x below enjoys
# extra precision, allowing it to be even smaller.
x = fabs(((FOUR / THREE - ONE) - ONE / FOUR) * THREE - ONE / FOUR)
doit = True
while doit:
z2 = x
x = (ONE + (ONE_HALF * z2 + THIRTY_TWO * z2 * z2)) - ONE
doit = (z2 > x) and (x > ZERO)
Part 4
# Now look at ulps of 1- by starting with rounding noise in 3/4.
# x, y, and z are used in the three following loops.
x = y = z = fabs((THREE / FOUR - TWO / THREE) * THREE - ONE / FOUR)
while True:
z1 = z
z = (ONE / TWO
- ((ONE / TWO - (ONE_HALF * z1 + THIRTY_TWO * z1 * z1))
+ ONE / TWO)) + ONE / TWO
if z1 <= z or z <= ZERO: break
Part 5
# BUG in BASIC and C version -- the two loops below are not nested,
# but simply in sequence with the z1 loop just above.
# See lines 1730 and 1740 in the BASIC, the latter line should branch
# back to itself.
while True:
y1 = y
y = (ONE_HALF - ((ONE_HALF - (ONE_HALF * y1 + THIRTY_TWO * y1 * y1))
+ ONE_HALF)) + ONE_HALF
print("1730: y1 = {:.17e} y = {:.17e}".format(y1, y))
if y1 <= y or y <= ZERO: break
while True:
x1 = x
x = ((ONE_HALF * x1 + THIRTY_TWO * x1 * x1)
- ONE_MINUS_ULP) + ONE_MINUS_ULP
print("1740: x1 = {:.17e} x = {:.17e}".format(x1, x))
if x1 <= x or x <= ZERO: break
Part 6
if x1 != y1 or x1 != z1:
bad_cond(err_serious, "Disagreements among the values x1, y1, z1,")
print("respectively {:0.7e}, {:0.7e}, {:0.7e},".format(x1, y1, z1))
print("are symptoms of inconsistencies introduced")
print("by extra-precise evaluation of arithmetic subexpressions.")
notify("Possibly some part of this")
if (x1 == ULP_OF_ONE_MINUS or y1 == ULP_OF_ONE_MINUS
or (z1 == ULP_OF_ONE_MINUS)):
print("That feature is not tested further by this program.\n")
Part 7
elif z1 != ULP_OF_ONE_MINUS or z2 != ULP_OF_ONE_PLUS:
if z1 >= ULP_OF_ONE_MINUS or z2 >= ULP_OF_ONE_PLUS:
bad_cond(err_failure, "")
notify("PRECISION")
print("\tULP_OF_ONE_MINUS = {:0.7e}, z1 - ULP_OF_ONE_MINUS = {:0.7e}".format(ULP_OF_ONE_MINUS,
z1 - ULP_OF_ONE_MINUS))
print("\tULP_OF_ONE_PLUS = {:0.7e}, z2 - ULP_OF_ONE_PLUS = {:0.7e}".format(ULP_OF_ONE_PLUS,
z2 - ULP_OF_ONE_PLUS))
Part 8
else:
if (z1 <= ZERO or z2 <= ZERO):
print("Because of unusual B = {:0.f}".format(B))
print(", or exact rational arithmetic a result")
print("z1 = {:0.7e}, or z2 = {:0.7e} ".format(z1, z2))
notify("of an extra-precision")
Part 9
if z1 != z2 or z1 > ZERO:
x = z1 / ULP_OF_ONE_MINUS
y = z2 / ULP_OF_ONE_PLUS
if y > x:
x = y
q = - log(x)
print("Some subexpressions appear to be calculated extra")
print("precisely with about {:.g} extra B-digits, i.e.",
(q / log(B)))
print("roughly {:.g} extra significant decimals."
.format(q / log(10.)))
print("That feature is not tested further by this program.")
Part 10