When dealing with numerical programming, one often is confronted with a conditional statement that requires a decision to be made based upon the difference or ratio between two variables being reasonably close to zero. The question then arises: how close is reasonably close? At first impulse, one may simply choose to select a tiny arbitrary value, say 10-6 or better yet 10-20 based upon the user's desire for precision. While this may seem like a acceptable method, it ignores the realities of the floating point representation being used by the machine.
Floating point numbers are ususally represented in binary as follows:
where 'S' is the sign bit, the 'Ei' are the exponent bits, and the 'Tj' are the significand bits (also known as the mantissa). This implies that there is a maximum relative spacing between any two numbers for a given floating point representation. Given a common floating point representation such as double precision IEEE found on standard personal computers, this maximum relative spacing is 2.22E-16, yielding 16 digits of precision. This value can be determined from the formula:
maximum relative spacing (epsilon) = 21-n
where 'n' is the number of bits in the significand (note that IEEE uses a "hidden bit method" so that while there are only 52 bits in a 64-bit number dedicated to the significand, the value of 'n' in that case is really 53).
So for programmable calculators like the HP 33s, knowing what epsilon is important. The manual states that typical calculations are accurate to 12 decimal digits. This would imply an epsilon value of around 10-12 to 10-13 or the number of significand bits being as low as 39 up to 41 bits. Mr. Hanson mentioned in his article about a "Cadillac" quadratic solver for the HP 33s that the "tricky properties" of the statistical operations allow precision up to 15 digits; more in line with the 52 to 53 bit significand used in the IEEE floats.
I attempted to ask HP directly about the number of bits used for the significand in the HP 33s for both sets of operations to no avail. I'm trying to come up with a nifty program to determine the appropriate value for 'n' for standard operations. If anyone comes up with something, please post it.
For the time being, the few programs I have written (Mr. Hanson's program translation being the exception) use:
Stay tuned for some programs that I've successfully translated to the HP 33s!