Thursday, January 8, 2009

floating point binary

from the math thread on smug earlier today... why MONEY doesn't compute

Here's my 2 cents on fuzzy computer math: (please feel free to ignore my ramblings)

Floating-point is a lot like scientific notation. It generally has a radix (coefficient), which can be adjustable and an exponent or scale. The radix is multiplied by the base to the power of the exponent.

Ex: 123456.7890 in ten digit precision = radix - 1234567890 with a exponent of 2 (the radix point follows the first digit).

So the value is 10^2*1.234567890 or 123456.7890

Because the radix point is adjustable the floating point notation the math gets fuzzy.

EX: 0.15 * 0.15 = 0.0225

In float point

EX: (1.5*10^-1)x(1.5*10^-1)=(2.25*10^-2)

Computers then use rounding modes to compute the results of floating point operations

In multiplication the radix is multiplied while the exponents are added and the result is rounded, small errors are reported as multiple operations are completed. The errors will occur then the exponent is either too large or too small resulting in hidden bit differences in the math. (side google note: Horner scheme computation for a great algorithm for floating point multiplication and division)

If you made it this far and didn't fall asleep, check out this book "What Every Computer Scientist Should Know About Floating Point Arithmetic" Goldberg, 1991... It's a great read if you enjoy this kinda stuff.

Or in the words of Xena... WIZARD!

1 comment:

Christine said...

Maybe this is top secret info, but to what decimal point does bank software round? I know we had to learn how to do both 16 and 32 bit floating point conversions by hand. 32 bit got excessive when it was 30 bits in the fraction part.

This reminds me of the convo we had on the way to get fish for sushi. Maybe I should stop asking questions :)