Professional Documents
Culture Documents
Decimal Division Binary Division: - Remember 4th Grade Long Division?
Decimal Division Binary Division: - Remember 4th Grade Long Division?
© 2012 Daniel J. Sorin ECE 152 © 2012 Daniel J. Sorin ECE 152
61 62
from Roth and Lebeck from Roth and Lebeck
Floating Point (FP) Numbers The World Before Floating Point
• Floating point numbers: numbers in scientific notation • Early computers were built for scientific calculations
• Two uses • ENIAC: ballistic firing tables
• Use #1: real numbers (numbers with non-zero fractions) • But didn’t have primitive floating point data types
• 3.1415926… • Circuits were big
• 2.1878… • Many accuracy problems
• 9.8
• 6.62 * 10–34 • Programmers built scale factors into programs
• 5.875 • Large constant multiplier turns all FP numbers to integers
• Before program starts, inputs multiplied by scale factor manually
• Use #2: really big numbers • After program finishes, outputs divided by scale factor manually
• 3.0 * 108 • Yuck!
• 6.02 * 1023
© 2012 Daniel J. Sorin ECE 152 © 2012 Daniel J. Sorin ECE 152
63 64
from Roth and Lebeck from Roth and Lebeck
© 2012 Daniel J. Sorin ECE 152 © 2012 Daniel J. Sorin ECE 152
67 68
from Roth and Lebeck from Roth and Lebeck
© 2012 Daniel J. Sorin ECE 152 © 2012 Daniel J. Sorin ECE 152
69 70
from Roth and Lebeck from Roth and Lebeck
Normalized Numbers More About Normalization
• Notice • What is –0.5 in normalized floating point?
• 5 is 1.25 * 22 • Sign: 1
• But isn’t it also 0.625 * 23 and 0.3125 * 24 and …? • 0.5 = 1 * 2–1
• With 8-bit exponent, we can have 8 representations of 5 • Significand: 1 = 1*20 = 100 0000 0000 0000 0000 0000
• Multiple representations for one number is bad idea • Exponent: -1 = 1111 1111 (assuming 2’s complement for now)
– Would lead to computational errors
– Would waste bits • IEEE 754: no need to represent coefficient of 20 explicitly
• Solution: choose normal (canonical) form • It’s always 1
• Disallow de-normalized numbers (some exceptions later) + Buy yourself an extra bit of precision
• IEEE 754 normal form: coefficient of 20 is always 1 • Pretty cute trick
• Similar to scientific notation: one non-zero digit left of decimal
• Normalized representation of 5 is 1.25 * 22 (1.25 = 1*20+1*2-2) • Problem: what about 0?
• 0.625 * 23 is de-normalized (0.625 = 0*20+1*2-1+ 1*2-3) • How can we represent 0 if 20 is always implicitly 1?
© 2012 Daniel J. Sorin ECE 152 © 2012 Daniel J. Sorin ECE 152
71 72
from Roth and Lebeck from Roth and Lebeck
© 2012 Daniel J. Sorin ECE 152 © 2012 Daniel J. Sorin ECE 152
75 76
from Roth and Lebeck from Roth and Lebeck
© 2012 Daniel J. Sorin ECE 152 © 2012 Daniel J. Sorin ECE 152
77 78
from Roth and Lebeck from Roth and Lebeck
FP Addition Decimal Example FP Addition (Quarter Precision) Example
• Let’s look at a decimal example first: 99.5 + 0.8 • Now a binary “quarter” example: 7.5 + 0.5
• 9.95*101 + 8.0*10-1 • 7.5 = 1.875*22 = 0 101 11110 (the 1 is the implicit leading 1)
• 1.875 = 1*20+1*2-1+1*2-2+1*2-3
• 0.5 = 1*2-1 = 0 010 10000
• Step I: align exponents (if necessary)
• Temporarily de-normalize operand with smaller exponent
• Add 2 to its exponent → must shift significand right by 2
• Step I: align exponents (if necessary)
• 0 010 10000 → 0 101 00010
• 8.0* 10-1 → 0.08*101
• Add 3 to exponent → shift significand right by 3
• Step II: add significands • Step II: add significands
• 9.95*101 + 0.08*101 → 10.03*101 • 0 101 11110 + 0 101 00010 = 0 101 100000
• Step III: normalize result • Step III: normalize result
• Shift significand right by 1 and then add 1 to exponent • 0 101 100000 → 0 110 10000
• 10.03*101 → 1.003*102 • Shift significand right by 1 → add 1 to exponent
© 2012 Daniel J. Sorin ECE 152 © 2012 Daniel J. Sorin ECE 152
79 80
from Roth and Lebeck from Roth and Lebeck