CS 230 - Spring 2020 1-1
Lecture 5 Floating Point Continued CS 230 - Spring 2020 1-1 - - PowerPoint PPT Presentation
Lecture 5 Floating Point Continued CS 230 - Spring 2020 1-1 - - PowerPoint PPT Presentation
CS 230 Introduction to Computers and Computer Systems Lecture 5 Floating Point Continued CS 230 - Spring 2020 1-1 Normalized Representation Why do we need to move the radix point to after the first 1 bit? Why is there a 1 in the
CS 230 - Spring 2020 1-2
Normalized Representation
Why do we need to move the radix point to after
the first 1 bit? Why is there a 1 in the formula?
(-1)S * 1.F * 2E-B
Let’s pretend it’s a zero: consider 1.012 In our example format it could be
(-1)0 * 0.1010 * 24-3 (-1)0 * 0.0101 * 25-3
Now we can’t compare bits for equality and we
waste the potential free 1 bit
CS 230 - Spring 2020 1-3
Normalized Representation Problem
What is the smallest positive number we can
represent in our example format?
(-1)S * 1.F * 2E-B
S=0 E=000 F=0001 (-1)0 * 1.0001 * 20-3 = 1.0001 * 2-3 = 0.00100012
How do we get rid of that 1?
It’s blocking all the small numbers We can’t just always use zero instead
CS 230 - Spring 2020 1-4
Solution: Subnormal
Only use zero when the number is too small Two forms of the floating point formula
Normal: (-1)S * (1 + F) * 2E-B Subnormal: (-1)S * (0 + F) * 21-B
How do we know when to use which form?
- When E is all zeros use subnormal
Why 1-B?
- We used up E=0 to mean subnormal, so now smallest
exponent is E=1 and we don’t want to leave a gap
CS 230 - Spring 2020 1-5
Special Cases
Overflow still possible (E too large)
represent as +/- infinity also for division by zero (by IEEE standard)
Invalid result – Not a Number – NaN
special cases, like 0/0 or ∞*0 or sqrt(-1) can “safely” propagate during computation
Both can propagate during computation
no exception (like integer division by zero)
CS 230 - Spring 2020 1-6
IEEE-754 Special Cases
Exponent Fraction Case 000000… 000000… 000000… non-zero subnormal 111111… 000000… infinity (+ or -) 111111… non-zero NaN anything else anything normal
CS 230 - Spring 2020 1-7
CS 230 - Spring 2020 1-8
CS 230 - Spring 2020 1-9
CS 230 - Spring 2020 1-10
CS 230 - Spring 2020 1-11
CS 230 - Spring 2020 1-12
CS 230 - Spring 2020 1-13
CS 230 - Spring 2020 1-14
CS 230 - Spring 2020 1-15
CS 230 - Spring 2020 1-16
CS 230 - Spring 2020 1-17
CS 230 - Spring 2020 1-18
CS 230 - Spring 2020 1-19
CS 230 - Spring 2020 1-20
CS 230 - Spring 2020 1-21
CS 230 - Spring 2020 1-22
CS 230 - Spring 2020 1-23
CS 230 - Spring 2020 1-24
CS 230 - Spring 2020 1-25
CS 230 - Spring 2020 1-26
CS 230 - Spring 2020 1-27
CS 230 - Spring 2020 1-28
CS 230 - Spring 2020 1-29
CS 230 - Spring 2020 1-30
CS 230 - Spring 2020 1-31
CS 230 - Spring 2020 1-32
CS 230 - Spring 2020 1-33
CS 230 - Spring 2020 1-34
CS 230 - Spring 2019 1-35
Floating Point Arithmetic
Addition
align radix points use normal addition
Multiplication
add exponents multiply significands
1.F if normal, 0.F if subnormal
CS 230 - Spring 2020 1-36
CS 230 - Spring 2020 1-37
CS 230 - Spring 2020 1-38
CS 230 - Spring 2020 1-39
CS 230 - Spring 2020 1-40
CS 230 - Spring 2020 1-41
CS 230 - Spring 2020 1-42
CS 230 - Spring 2020 1-43
CS 230 - Spring 2020 1-44
CS 230 - Spring 2020 1-45
CS 230 - Spring 2020 1-46
CS 230 - Spring 2020 1-47
CS 230 - Spring 2020 1-48
CS 230 - Spring 2020 1-49
CS 230 - Spring 2020 1-50
CS 230 - Spring 2020 1-51
CS 230 - Spring 2020 1-52
CS 230 - Spring 2020 1-53
CS 230 - Spring 2020 1-54
CS 230 - Spring 2020 1-55
CS 230 - Spring 2020 1-56
CS 230 - Spring 2020 1-57
CS 230 - Spring 2020 1-58
CS 230 - Spring 2020 1-59
CS 230 - Spring 2020 1-60
CS 230 - Spring 2020 1-61
CS 230 - Spring 2020 1-62
CS 230 - Spring 2020 1-63
CS 230 - Spring 2020 1-64
CS 230 - Spring 2020 1-65
CS 230 - Spring 2020 1-66
CS 230 - Spring 2020 1-67