11.001001000011111101101010100010001000 Arithmazium
Home

This is an automatically generated file.

Part 1

Part 2

def test_mult_commutivity(count):
    """Run some random tests to check that x*y = y*x. """
    global rand_next, rand_seed
    rand_seed = sqrt(3.0)
    rand_next = ONE / THREE

Part 3

    i = 0
    doit = True
    while doit:
        x = rand_frac()
        y = rand_frac()
        yx = y * x
        xy = x * y
        xyyx = xy - yx
        i = i + 1
        doit = (i < count) and (xyyx == ZERO)

Part 4

    if (xyyx == ZERO):
        # One rather less random test lays out the operands, products,
        # and the computed difference.
        x = ONE + ONE_HALF / THREE
        y = (ULP_OF_ONE_PLUS + ULP_OF_ONE_MINUS) + ONE
        xy = x * y
        yx = y * x
        xyyx = ((ONE + ONE_HALF / THREE)
                * ((ULP_OF_ONE_PLUS + ULP_OF_ONE_MINUS) + ONE)
                - ((ULP_OF_ONE_PLUS + ULP_OF_ONE_MINUS) + ONE)
                * (ONE + ONE_HALF / THREE))

Part 5

    # In the usual case, count random tests and 1 extra test are run.
    # xyyx is the final arbiter of success.
    if xyyx != ZERO:
        print("x * y == y * x fails for x = {:0.17e}  y = {:0.17e}"
              .format(x, y))
        print("    x * y = {:0.17e}  y * x = {:0.17e}".format(xy, yx))
        print("    and x * y - y * x = {:0.17e}".format(xyyx))
        bad_cond(err_defect, "x * y == y * x trial fails.")
    else:
        print("     No failures found in {:d} integer pairs.".format(count + 1))


Part 6

Home