This is an automatically generated file.
Part 1
Part 2
def test_sqrt_monotonicity():
"""Test for monotonicity around the radix B."""
i = - 1
x = B_MINUS_ULP
y = B
z = B + B * ULP_OF_ONE_PLUS # B plus 1 ulp
not_monot = False
monot = False
Part 3
while not (not_monot or monot):
i = i + 1
# CASE: y = B
x = sqrt(x)
q = sqrt(y)
z = sqrt(z)
if x > q or q > z:
not_monot = True
Part 4
else:
q = floor(q + ONE_HALF)
# B = q*q only if radix B is 16 or 4
if (i <= 0) and (B != q * q):
monot = True # exit early unless B is 16 or 4
Part 5
elif i <= 0:
# CASE: y = sqrt(B), if B = 4, 16 or other square
y = q
x = y - ULP_OF_ONE_PLUS
z = y + ULP_OF_ONE_PLUS
Part 6
elif i == 1:
# CASE: 7 = 1/sqrt(B), if B = 4, 16, or other square
y = y * ONE_OVER_B
x = y - ULP_OF_ONE_MINUS
z = y + ULP_OF_ONE_MINUS
else:
# Have survived three cases
monot = True
Part 7
if monot:
print("sqrt has passed a test for Monotonicity.")
else:
bad_cond(err_defect, "")
print("sqrt(x) is non-monotonic for x near {:0.7e} .".format(y))
Part 8