11.001001000011111101101010100010001000 Arithmazium
Home

This is an automatically generated file.

Part 1

Part 2

milestone = 85  # ==============================
sqrt_rnd_odd = False
sqrt_anomalous_int = False
tests = 0
flags["sqrt_rounding"] = "other"
while B != ONE:
    print("Testing whether sqrt is rounded or chopped.")
    D = floor(ONE_HALF + pow(B, ONE + PRECISION - floor(PRECISION)))
    # ... == B^(1 + fract) if (PRECISION == Integer + fract.
    x = D / B
    y = D / A
    if x != floor(x) or y != floor(y):
        sqrt_anomalous_int = True
        break

Part 3

    x = ZERO
    z2 = x
    y = ONE
    y2 = y
    # **** B = 8   #**********************************************
    # *** D = 16   #**********************************************
    z1 = B - ONE
    FourD = FOUR * D

Part 4

    while True:
        if (y2 > z2):
            Q = B
            y1 = y
            while True:
                x1 = fabs(Q + floor(ONE_HALF - Q / y1) * y1)
                Q = y1
                y1 = x1
                if ultra_verbose:
                    print("\t\t\tloop inner x1 = {:.6e} Q = {:.6e} y1 = {:.6e}"
                          .format(x1, Q, y1))
                if x1 <= ZERO: break
            if (Q <= ONE):
                z2 = y2
                z = y

Part 5

        y = y + TWO
        x = x + EIGHT
        y2 = y2 + x
        if y2 >= FourD:
            y2 = y2 - FourD
        if ultra_verbose:
            print("\t\t\tloop x = {:.6e} x1 = {:.6e}".format(x, x1))
            print("\t\t\t     y = {:.6e} y1 = {:.6e} y2 = {:.6e}".format(y, y1, y2))
            print("\t\t\t     z = {:.6e} z1 = {:.6e} z2 = {:.6e}".format(z, z1, z2))
        if y >= D: break

Part 6

    X8 = FourD - z2
    # ***JTC: fix global Q used by num_theory_sqrt_value
    Q = (X8 + z * z) / FourD
    X8 = X8 / EIGHT
    if ultra_verbose:
        print("Loop finds Q = {:.17e} X8 = {:.17e}".format(Q, X8))
    if Q != floor(Q):
        sqrt_anomalous_int = True
        break

Part 7

    while True:
        x = z1 * z
        x = x - floor(x / B) * B
        if x != ONE:
            z1 = z1 - ONE
        if x == ONE or z1 <= ZERO: break
    if z1 <= ZERO and x != ONE:
        sqrt_anomalous_int = True
        break

Part 8

    if z1 > B_OVER_TWO:
        z1 = z1 - B
    while True:
        x, D, Q, z, z1 = num_theory_sqrt_value(x, D, Q, z, z1)
        if ULP_OF_ONE_PLUS * D >= ONE_MINUS_ULP: break
    if D * B - D != BIG_B_NTH - D:
        sqrt_anomalous_int = True
        break

Part 9

    z2 = D
    y = D + (ONE + z) * ONE_HALF
    x = D + z + Q
    tests += num_theory_sqrt_test(x, D, y, z2)
    y = D + (ONE - z) * ONE_HALF + D
    x = D - z + D
    x = x + Q + x
    tests += num_theory_sqrt_test(x, D, y, z2)
    x, D, Q, z, z1 = num_theory_sqrt_value(x, D, Q, z, z1)
    if D - z2 != BIG_B_NTH - z2:
        sqrt_anomalous_int = True
        break

Part 10

    y = (D - z2) + (z2 + (ONE - z) * ONE_HALF)
    x = (D - z2) + (z2 - z + Q)
    tests += num_theory_sqrt_test(x, D, y, z2)
    y = (ONE + z) * ONE_HALF
    x = Q
    tests += num_theory_sqrt_test(x, D, y, z2)
    break  # exit ficttitious loop in one pass

Part 11

if verbose:
    print("\tAfter all sqrt test computations:")
    print("\t\tmin_sqrt_error = {:0.17e}".format(min_sqrt_error))
    print("\t\tmax_sqrt_error = {:0.17e}".format(max_sqrt_error))
if tests == 0 or sqrt_anomalous_int:
    bad_cond(err_failure, "Anomalous arithmetic with Integer < ")
    print("B^PRECISION = {:0.7e}".format(BIG_B_NTH))
    print(" fails test whether sqrt rounds or chops.")
    sqrt_rnd_odd = True
else:
    if min_sqrt_error >= ZERO and max_sqrt_error <= ZERO:
        flags["sqrt_rounding"] = "rounded"
        print("Square root appears to be correctly rounded.")
    else:
        if (max_sqrt_error + ULP_OF_ONE_PLUS > ULP_OF_ONE_PLUS - ONE_HALF
                or min_sqrt_error > ONE_HALF
                or min_sqrt_error + B < ONE_HALF):
            sqrt_rnd_odd = True
        else:
            flags["sqrt_rounding"] = "chopped"
            print("Square root appears to be chopped.")

Part 12

if sqrt_rnd_odd:
    print("Square root is neither chopped nor correctly rounded.")
    print("Observed errors run from {:0.7e} "
          .format(min_sqrt_error - ONE_HALF), end="")
    print("to {:0.7e} ulps.".format(ONE_HALF + max_sqrt_error))
    test_cond(err_serious, max_sqrt_error - min_sqrt_error < B * B,
              "sqrt gets too many last digits wrong")

Part 13

Home