11.001001000011111101101010100010001000 Arithmazium
Home

This is an automatically generated file.

Part 1

Part 2

def does_tiny_value_misbehave(z):
    """Check for abnormal behavior of a value presumed
    to be tiny or zero.

    Given a value z, check that (z + z)/z is 2.0 or very close, and that
    1.0*z = z*1.0 = z/1.0 = z. This is especially interesting near the
    underflow threshold, but the function should work unless z is so
    huge that doubling it overflows.

    Args:
        z - test value

    Returns:
        boolean reply to the question

    Basic 4640-4680
    """

Part 3

    reply = False
    if z == ZERO:  # nothing complex to test in the easy case
        return reply
    print("Since comparison denies z = 0, evaluating ", end="")
    print("(z + z) / z should be safe.")
    z_quo = ONE
    try:
        z_quo = (z + z) / z
    except ZeroDivisionError:
        reply = True
        error_count[err_serious] = error_count[err_serious] + 1
        print("But the division triggered an exception.")
        print("This is a VERY SERIOUS DEFECT!")

    print("What the machine gets for (z + z) / z is  {:0.17e} ."
          .format(z_quo))
    if fabs(z_quo - TWO) < B * ULP_OF_ONE_PLUS:
        print("This is O.K., provided Over/Underflow", end="")
        print(" has NOT just been signaled.")
    else:
        reply = True
        if z_quo < ONE or z_quo > TWO:
            error_count[err_serious] = error_count[err_serious] + 1
            print("This is a VERY SERIOUS DEFECT!")
        else:
            error_count[err_defect] = error_count[err_defect] + 1
            print("This is a DEFECT!")

Part 4

    r1 = z * ONE
    r2 = ONE * z
    r3 = z / ONE
    if (z == r1) and (z == r2) and (z == r3):
        if reply:
            pause()
    else:
        reply = True
        bad_cond(err_defect, "What prints as z = ", end="")
        print("{:0.17e}\n\tcompares different from  ".format(z))
        if z != r1:
            print("z * 1 = {:0.17e} ".format(r1))
        if (z != r2) and (r2 != r1):
            print("1 * z == {:0.17e}".format(r2))
        if z != r3:
            print("z / 1 = {:0.17e}".format(r3))
        if r2 != r1:
            error_count[err_defect] = error_count[err_defect] + 1
            bad_cond(err_defect, "Multiplication does not commute!\n")
            print("\tComparison alleges that 1 * z = {:0.17e}"
                  .format(r2))
            print("\tdiffers from z * 1 = {:0.17e}".format(r1))
        pause()
    return reply


Part 5

Home