11.001001000011111101101010100010001000 Arithmazium
Home

Useful constants

We'll use these values throughout the rest of the code.

B_MINUS_ULP is the next value smaller than the radix. The diagram expands the code to show how decrementing B allows the subtraction to be carried out entirely within PRECISION digits. It should be exact on any machine that survives the tests that follow.

x = B - ONE    900000 one ulp is same as ulp of 1+ y = x - ULP_OF_ONE_PLUS    899999 exact value B_MINUS_ULP = y + ONE    999999 = B - ULP_OF_ONE_PLUS

Value C is a tiny value at least a factor of B**PRECISION above values that can underflow to zero or subnormal numbers. Refer to the function for more color.

milestone = 25  # ==============================
# ... B_MINUS_ULP = nextafter(B, 0)
B_MINUS_ULP = B - ONE
B_MINUS_ULP = (B_MINUS_ULP - ULP_OF_ONE_PLUS) + ONE
# A = 2 if B = 2**k or arithmetic is logarithmic; it's 10 if B=10
# C = 1/B**k not too close to underflow, useful for over/underflow analysis.
# H = min(1/B, 1/2).
A, ONE_OVER_A = compute_A_and_inverse(B)
C, ONE_OVER_C = compute_C_and_inverse()
H, ONE_OVER_H = compute_H_and_inverse()
SAFE_ULPS_OF_ONE = compute_safe_ulps_of_one()  # 1 or B ulps of one

Your turn

Exercise: Compute B_MINUS_ULP in binary arithmetic, given the helpful start.

x = B - ONE    100 ... 0 B = 2 y = x - ULP_OF_ONE_PLUS    011 ... ??? what are the low-order bits? B_MINUS_ULP = y + ONE    ??? ... ??? how many 1 bits are there?
Home