Division Computed Hex Binary x 15213 15213 3B 6D 00111011 01101101 x 1 76065

Division computed hex binary x 15213 15213 3b 6d

This preview shows page 58 - 75 out of 77 pages.

Division Computed Hex Binary x 15213 15213 3B 6D 00111011 01101101 x >> 1 7606.5 7606 1D B6 00011101 10110110 x >> 4 950.8125 950 03 B6 00000011 10110110 x >> 8 59.4257813 59 00 3B 00000000 00111011 Examples:
Image of page 58
shrl $3, %eax Compiled Unsigned Division Code Uses logical shift for unsigned For Java Users Logical shift written as >>> unsigned udiv8(unsigned x) { return x/8; } # Logical shift return x >> 3; C Function Compiled Arithmetic Operations Explanation
Image of page 59
Signed Power-of-2 Divide with Shift Quotient of Signed by Power of 2 x >> k gives x / 2 k Uses arithmetic shift Examples Division Computed Hex Binary y -15213 -15213 C4 93 11000100 10010011 y >> 1 -7606.5 -7607 E2 49 1 1100010 01001001 y >> 4 -950.8125 -951 FC 49 1111 1100 01001001 y >> 8 -59.4257813 -60 FF C4 11111111 11000100
Image of page 60
Floating Points Some slides and information about FP are adopted from Prof. Michael Overton book: Numerical Computing with IEEE Floating Point Arithmetic
Image of page 61
Turing Award 1989 to William Kahan for design of the IEEE Floating Point Standards 754 (binary) and 854 (decimal)
Image of page 62
Carnegie Mellon Background: Fractional binary numbers What is 1011.101 2 ?
Image of page 63
2 i 2 i-1 4 2 1 1/2 1/4 1/8 2 -j b i b i-1 ••• b 2 b 1 b 0 b -1 b -2 b -3 ••• b -j Carnegie Mellon • • • Background: Fractional Binary Numbers Value: • • •
Image of page 64
Carnegie Mellon Fractional Binary Numbers: Examples Value Representation 5 3/4 101.11 2 2 7/8 10.111 2
Image of page 65
Carnegie Mellon Why not fractional binary numbers? Not efficient 3 * 2 100 1010000000 ….. 0 Given a finite length (e.g. 32-bits), cannot represent very large nor very small numbers ( ε 0) 100 zeros
Image of page 66
Carnegie Mellon IEEE Floating Point IEEE Standard 754 Supported by all major CPUs The IEEE standards committee consisted mostly of hardware people, plus a few academics led by W. Kahan at Berkeley. Main goals: Consistent representation of floating point numbers by all machines . Correctly rounded floating point operations. Consistent treatment of exceptional situations such as division by zero.
Image of page 67