# An example that tells it all: # 1 + 1/20 = 1.05 = 1.00 0011 : bit52 = 0, bit53 = 1 # 1 + 1/40 = 1.025 = 1.000 0011 : bit52 = 0, bit53 = 0 # 1 + 1/80 = 1.0125 = 1.0000 0011 : bit52 = 1, bit53 = 0 # 1 + 1/160 = 1.00625 = 1.00000 0011 : bit52 = 1, bit53 = 1 # where # 1.00 0011 means # 1.000011001100110011001100110011001100110011... base 2, # and similarly for the other binary representations. # Also bit52 and bit53 are the 52nd and 53rd bits after the point.
# The results: printf "%.1f\n", 1.05; # produces 1.1 printf "%.2f\n", 1.025; # produces 1.02 printf "%.3f\n", 1.0125; # produces 1.012 printf "%.4f\n", 1.00625; # produces 1.0063
# This is 52-bit precision with rounding arithmetic. Sprintf rounds a # number up or down according as the 53rd bit in the binary # representation of the number is set or not. (The 52nd bit would be # the indicator with 52-bit precision and truncating arithmetic.)
-- *---* mailto:[EMAIL PROTECTED] | Victor Thane Norton, Jr. | Mathematician and Motorcyclist | phone: 419-353-3399 *---* http://vic.norton.name