This is an automatically generated file.
Part 1
Part 2
def how_does_div_round():
"""Check for rounding in division.
Returns:
"rounded", "chopped", "other"
"""
Part 3
rdiv = "other"
y2 = ONE + ULP_OF_ONE_PLUS
y1 = ONE - ULP_OF_ONE_PLUS
z = ONE_AND_HALF + ULP_OF_ONE_PLUS + ULP_OF_ONE_PLUS
x = z / y2
t = ONE_AND_HALF - ULP_OF_ONE_PLUS - ULP_OF_ONE_PLUS
y = (t - ULP_OF_ONE_PLUS) / y1
z = (z + ULP_OF_ONE_PLUS) / y2
Part 4
x = x - ONE_AND_HALF
y = y - t
t = t / y1
z = z - (ONE_AND_HALF + ULP_OF_ONE_PLUS)
t = (ULP_OF_ONE_PLUS - ONE_AND_HALF) + t
Part 5
if not ((x > ZERO) or (y > ZERO) or z > ZERO or t > ZERO):
x = ONE_AND_HALF / y2
y = ONE_AND_HALF - ULP_OF_ONE_PLUS
z = ONE_AND_HALF + ULP_OF_ONE_PLUS
x = x - y
t = ONE_AND_HALF / y1
y = y / y1
t = t - (z + ULP_OF_ONE_PLUS)
Part 6
y = y - z
z = z / y2
y1 = (y2 + ULP_OF_ONE_PLUS) / y2
z = z - ONE_AND_HALF
y2 = y1 - y2
y1 = (ONE_MINUS_ULP - ULP_OF_ONE_MINUS) / ONE_MINUS_ULP
Part 7
if ((x == ZERO) and (y == ZERO) and (z == ZERO) and (t == ZERO)
and (y2 == ZERO) # BUG in C version: duplicate test
and (y1 - ONE_HALF == ONE_MINUS_ULP - ONE_HALF)):
rdiv = "rounded"
print("Division appears to round correctly. ")
if not flags["div_guard_digit"]:
notify("Division")
Part 8
elif ((x < ZERO) and (y < ZERO) and (z < ZERO) and (t < ZERO)
and (y2 < ZERO) and (y1 - ONE_HALF < ONE_MINUS_ULP - ONE_HALF)):
rdiv = "chopped"
print("Division appears to chop. ")
Part 9
if rdiv == "other":
print("/ is neither chopped nor correctly rounded. ")
return rdiv
Part 10