This is an automatically generated file.
Part 1
Part 2
print("Testing if sqrt(x * x) == x for {:d} Integers x.".format(NUM_TRIALS))
test_sqrt_int()
print("Test for sqrt monotonicity.")
test_sqrt_monotonicity()
milestone = 80 # ==============================
if verbose:
print("\tAfter monotonicity test:")
print("\t\tmin_sqrt_error = {:0.6e}".format(min_sqrt_error))
print("\t\tmax_sqrt_error = {:0.6e}".format(max_sqrt_error))
Part 3
print("Test sqrt for accuracy.")
# TODO: explain this bump - scaling?
min_sqrt_error = min_sqrt_error + ONE_HALF
max_sqrt_error = max_sqrt_error - ONE_HALF
y = (sqrt(ONE + ULP_OF_ONE_PLUS) - ONE) / ULP_OF_ONE_PLUS
up_err = (y - ONE) + ULP_OF_ONE_PLUS / EIGHT
down_err = y + ULP_OF_ONE_PLUS / EIGHT
update_sqrt_errors(down_err, up_err)
if verbose:
print("\tAfter 1 + ulp test:")
print("\t\tmin_sqrt_error = {:0.17e}".format(min_sqrt_error))
print("\t\tmax_sqrt_error = {:0.17e}".format(max_sqrt_error))
Part 4
y = (((sqrt(ONE_MINUS_ULP) - ULP_OF_ONE_PLUS) - (ONE - ULP_OF_ONE_PLUS))
/ ULP_OF_ONE_MINUS)
if verbose:
print("sqrt(1-ulp) = {:0.17e}".format(sqrt(ONE_MINUS_ULP)))
print("y = {:0.17e}".format(y))
up_err = y + ULP_OF_ONE_MINUS / EIGHT
down_err = (y + ONE) + ULP_OF_ONE_MINUS / EIGHT
update_sqrt_errors(down_err, up_err)
if verbose:
print("\tAfter 1 - ulp test:")
print("\t\tmin_sqrt_error = {:0.17e}".format(min_sqrt_error))
print("\t\tmax_sqrt_error = {:0.17e}".format(max_sqrt_error))
Part 5
ulp = ULP_OF_ONE_PLUS
x = ulp
for (x, ulp) in [(ULP_OF_ONE_PLUS, ULP_OF_ONE_PLUS),
(ULP_OF_ONE_PLUS
* floor(EIGHT / (NINE * sqrt(ULP_OF_ONE_PLUS))),
ULP_OF_ONE_PLUS),
(-ULP_OF_ONE_MINUS, ULP_OF_ONE_MINUS)]:
if verbose:
print("\t3-term sqrt loop: x = {:.17e} ulp = {:.17e}".format(x, ulp))
y = sqrt((x + ULP_OF_ONE_MINUS + x) + ONE_MINUS_ULP)
y = ((y - ULP_OF_ONE_PLUS) - ((ONE - ULP_OF_ONE_PLUS) + x)) / ulp
z = ((ULP_OF_ONE_MINUS - x) + ONE_MINUS_ULP) * ONE_HALF * x * x / ulp
down_err = (y + ONE_HALF) + z
up_err = (y - ONE_HALF) + z
update_sqrt_errors(down_err, up_err)
if verbose:
print("\tAfter ulp of 1+ cases")
print("\t\tmin_sqrt_error = {:0.17e}".format(min_sqrt_error))
print("\t\tmax_sqrt_error = {:0.17e}".format(max_sqrt_error))
Part 6