COA - Unit2 Floating Point Arithmetic 3
COA - Unit2 Floating Point Arithmetic 3
• Today’s topics:
Division
IEEE 754 representations
FP arithmetic
1
Divide Example
• Divide 7ten (0000 0111two) by 2ten (0010two)
Iter Step Quot Divisor Remainder
0 Initial values 0000 0010 0000 0000 0111
1 Rem = Rem – Div 0000 0010 0000 1110 0111
Rem < 0 +Div, shift 0 into Q 0000 0010 0000 0000 0111
Shift Div right 0000 0001 0000 0000 0111
2 Same steps as 1 0000 0001 0000 1111 0111
0000 0001 0000 0000 0111
0000 0000 1000 0000 0111
3 Same steps as 1 0000 0000 0100 0000 0111
4 Rem = Rem – Div 0000 0000 0100 0000 0011
Rem >= 0 shift 1 into Q 0001 0000 0100 0000 0011
Shift Div right 0001 0000 0010 0000 0011
5 Same steps as 4 0011 0000 0001 0000 0001
2
Hardware for Division
4
Divisions involving Negatives
5
Divisions involving Negatives
6
Floating Point
7
Sign and Magnitude Representation
9
Sign and Magnitude Representation
Sign Exponent Fraction
1 bit 8 bits 23 bits
S E F
• The number “0” has a special code so that the implicit 1 does not
get added: the code is all 0s
(it may seem that this takes up the representation for 1.0, but
given how the exponent is represented, we’ll soon see that
that’s not the case)
(see discussion of denorms (pg. 222) in the textbook)
• The largest exponent value (with zero fraction) represents +/- infinity
• Note that these choices impact the smallest and largest numbers
that can be represented
11
Exponent Representation
12
Examples
Single: (1 + 8 + 23)
Double: (1 + 11 + 52)
Single: (1 + 8 + 23)
1 0111 1110 1000…000
Double: (1 + 11 + 52)
1 0111 1111 110 1000…000
• Similar steps:
Compute exponent (careful!)
Multiply significands (set the binary point correctly)
Normalize
Round (potentially re-normalize)
Assign sign
17
MIPS Instructions
18
Code Example
19