Floating point numbers
Article Index
Floating point numbers
The radix
Binary fractions
Algorithms

 

Binary numbers are almost boring! Well that’s a common sentiment among high-level language programmers but then they don’t have to go delving into the depths of exactly how the machine does arithmetic. What usually happens is that their disinterest comes back to haunt them at the point when it is most inconvenient.

You need to know a little about how the simple binary counting numbers can be turned into the sort of numbers every banker, scientist and engineer knows and loves.

Other articles cover how to do arithmetic in simple binary and how to represent negative numbers using one's or two's complement so that they don’t need special treatment when performing arithmetic. One of the things I haven't already mentioned is that with only a little extra trouble we can make two's complement work with multiplication and division so that the usual rules of arithmetic, i.e. a minus times a minus is a plus, work automatically.

However, if you use the obvious algorithms that work for positive numbers the extra trouble that you have to go to seems very complex and involves adding different correction factors depending on the signs of the values involved in the result.

A much simpler method exists. Booth’s algorithm, invented in 1951, always gives you the correct answers no matter what the sign. I say simple but while the algorithm may be simple to perform it isn’t easy to see how it actually works. see Computer Arithmetic Algorithms (2001) by Israel Koren which also goes into more detail about other concepts introduced here.

BOOTH

Andrew Booth invented an easy way to multiply and divide

Fractions

So with this complication out of the way it looks as though the matter is closed – but what about fractions?

Inconvenient though they may be, fractions are the real stuff of number. After you have mastered the infantile art of counting whole things and adding, subtracting, multiplying and dividing whole things then you have to move on to arithmetic that involves fractions.

I could at this point tell you all about the mathematical theory of rational and irrational numbers and tell you how they were invented and why, but this would be just a diversion from the main problem. As far as a computer is concerned there are only rational numbers and rational approximations to irrational numbers so let’s stay simple and worry about the representation of rational fractions.

Rational fractions

The first notation that we use for fractions is based on the operation of division. We write a/b to stand for the fraction that you get when you divide a by b.

As this is a “ratio” this sort of fraction is referred to as “rational”.

There is an alternative way of representing a rational fraction using the place value system that we have come to rely on in both decimal and binary. What is surprising is that this well-known and almost obvious method took a great deal of time to invent and catch on.

The first mention of the idea of a decimal point occurs in the 10th century but it didn’t prove popular and it was forgotten. Decimals appeared again in the 15th century as “the Turkish” method. It took until the 16th century and many re-inventions of the idea before it started to make sense to the people who had to use it.

But it wasn’t until the 17th century and the invention of logarithms that the decimal point became at all common.

<ASIN: 1568811608>



 
 

   
Banner
RSS feed of all content
I Programmer - full contents
Copyright © 2012 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.