Download CompOrgW3LArith Floa..

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Mathematics of radio engineering wikipedia , lookup

Approximations of π wikipedia , lookup

Rounding wikipedia , lookup

Large numbers wikipedia , lookup

Elementary arithmetic wikipedia , lookup

Positional notation wikipedia , lookup

Location arithmetic wikipedia , lookup

Addition wikipedia , lookup

Elementary mathematics wikipedia , lookup

Arithmetic wikipedia , lookup

Transcript
Computer Organization 1
Computer Arithmetic in Floating
Point
Floating point addition and subtraction





This differs from integer arithmetic because
exponents have to be dealt with, as well as the
magnitudes of the operands.
To add and subtract, the exponents must first be
made equal.
E.g. Add 0.11011 x 2^5 to 0.10001 x 2^4
Start by adjusting the smaller exponent to equal
the larger exponent and adjust the fraction
accordingly:
Add .11011 x 2^5 to 0.010001 x 2^5
Floating point addition and subtraction






Add .11011 x 2^5 to 0.010001 x 2^5
Since both exponents are now equal, we can
add the fractions:
.11011
+ .010001
--------1.000111 x 2 ^5 = 0.1000111 x 2^6
Floating Point Multiplication and Division






Similar to addition and subtraction, except that sign,
exponent and fraction can be computed separately.
Signs equal: sign of result is positive
Signs different : negative sign for result
Exponent:
Multiplication : Add exponents of operands to give result
exponent
Division : Subtract the divisor exponent from the dividend
to give the result exponent.
Floating Point Multiplication and Division







Fractions: Multiply or Divide, then normalise
use 3-bit fractions in the following:
eg Multiply 0.101 x 2^2 by –0.110 x 2 ^-3
Operand Signs differ, so result will have -ve sign.
Add exponents for multiplication: 2+ (-3) = -1 is
the result exponent.
Multiply fractions: 0.101 x 0.110 gives 0.01111
If we normalise this product and retain only 3 bits
we get: 0.111 x 2 ^-2
Why do floating point numbers in computers
have such ‘complicated’ formats?



Now that we have seen how floating point arithmetic
is achieved, we see that before any calculating, the
number must be unpacked from the form it takes in
storage. The exponent and the fraction must be
extracted, the arithmetic done, and then the result
renormalized and rounded, and the bit patterns
repacked into the required format.
With FP format however, comparisons of two FP
numbers can be carried out without unpacking.
Eg Compare (0.100 x 2 ^4) with ( 0.110 x 2 ^5)
Why do floating point numbers in computers
have such complicated formats?

Eg Compare (0.100 x 2 ^4) with ( 0.110 x 2 ^5)
The FP (normalised) formats are :
S Exp
Fraction
0 1000 0100 000 0000 0000 etc for 0.100 x 2 ^4
0 1000 0101 100 0000 0000 etc for 0.110 x 2 ^5

Thus the second number is greater. (See this bit)




Why do floating point numbers in computers
have such complicated formats?







Compare (0.100 x 2 ^4) with ( - 0.110 x 2 ^5)
The FP (normalised) formats are :
S Exp
Fraction
0 1000 0100 000 0000 0000 etc for 0.100 x 2 ^4
1 1000 0110 100 0000 0000 etc for- 0.110 x 2 ^5
The sign of the number is the most important in making
comparisons, and appropriately is the MSB.
Next most important is the exponent because a change of +/1 in the exponent changes the value of the number by a
factor of 2, whereas a change in the MSB of the fraction
changes the value of the FP number by less than a factor of 2.
Get your conversions done free


http://babbage.cs.qc.edu/IEEE754/References.xhtml
- Converts decimal numbers to excess 127
floating point formats, single and double
precision
Summary








We have seen how data is represented in computers,
and the reasons for the different representations.
For example, 5 may be held as
1. a one-byte ASCII character, (as 0011 0101 in “95
O’Connell St”), no computation ‘allowed’;
2. A one byte pure binary integer 0000 0101;
3. A two or 4 byte Pure binary integer;
4. A Packed Decimal digit 0101;
5. 5.0 in 32 bit floating point:
0 1000 0011
010 0000 0000 0000 0000 0000