This is an automatically generated file.
Part 1
Part 2
def test_x_to_xp1_over_xm1(e2):
""" Compare x^(x+1)/(x-1) to exp(2) for x above and below 1.
Args:
e2: computed value of exp(2)
Basic 5360-5440
"""
print("Testing x^((x + 1) / (x - 1)) vs. " +
"exp(2) = {:0.12f} as x -> 1.".format(exp2))
# BUG: x runs away from 1, perhaps "x near 1"?
# Run tests below 1, then above 1, with a start value
# and a next value one ulp away.
if verbose:
print("Looping on values just below and just above 1.")
for x, next_x in [(ONE_MINUS_ULP, ONE_MINUS_ULP - ULP_OF_ONE_MINUS),
(ONE + ULP_OF_ONE_PLUS,
ONE + ULP_OF_ONE_PLUS + ULP_OF_ONE_PLUS)]:
Part 3
test_cnt = 1
while True:
z = x - ONE_OVER_B
z = (x + ONE) / (z - (ONE - ONE_OVER_B))
dev = pow(x, z) - exp2
if verbose:
print("\tx = {:.17f} z = {:.6e} deviation of".format(x, z)
+ " x^z = {:.3e}".format(dev))
Part 4
if (fabs(dev) > TWOFORTY * ULP_OF_ONE_PLUS):
delta_x = (x - ONE_OVER_B) - (ONE - ONE_OVER_B)
bad_cond(err_defect, "Calculated")
print(" {:0.17e} for".format(pow(x, z)))
print("\t(1 + ({:0.17e}) ^ ({:0.17e});".format(delta_x, z))
print("\tdiffers from correct value by {:0.17e} ."
.format(dev))
print("\tThis much error may spoil financial")
print("\tcalculations involving tiny interest rates.")
return
Part 5
else:
# Jump by 1 ulp, then 2, then 4, etc.
z = (next_x - x) * TWO + next_x
x = next_x
next_x = z
z = ONE + (x - ONE_MINUS_ULP) * (x - ONE_MINUS_ULP)
# *** BUG: P has (z > ONE), which means test done once only.
# Keep testing until too close to 1 or count too big.
if (z <= ONE) and (test_cnt < NUM_TRIALS):
test_cnt += 1
else:
break
# BUG: removed unneeded error flag if N == 0:
print("Accuracy seems adequate.")
return
Part 6