1 floating point operations - part ii. multiplication do unsigned multiplication on the mantissas...

13
1 Floating Point Floating Point Operations - Part Operations - Part II II

Upload: june-cross

Post on 14-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

1

Floating Point Floating Point Operations - Part Operations - Part

IIII

Page 2: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

MultiplicationMultiplication

Do unsigned multiplication on the Do unsigned multiplication on the mantissas including the hidden bitsmantissas including the hidden bits

Add the true exponents or unbias Add the true exponents or unbias one of the exponents (subtract 127 one of the exponents (subtract 127 from it) then perform 2’s from it) then perform 2’s complement additioncomplement addition

Normalize the resultNormalize the result Set the sign bit of the resultSet the sign bit of the result

Page 3: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

Setting the Sign bitSetting the Sign bit

The following table gives the sign bit The following table gives the sign bit of the result:of the result:

firstsign bit

secondsign bit

resultsign bit

0 0 0

1 0 1

0 1 1

1 1 0

Page 4: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

Example 12.5Example 12.518.0 x 9.518.0 x 9.5

1001000010010000

0 1000 0011 (1)001 00000 1000 0011 (1)001 0000 xx 10011000 10011000

0 1000 0010 (1)001 1000 100100000 1000 0010 (1)001 1000 10010000

0 0 1000 01101000 0110 (1)010 1011(1)010 1011 10010000 10010000

1001000010010000

101010111010101100000000000000

1000 00111000 0011

0000 00110000 0011

1000 01101000 0110

least 16 bits eliminated

Unbias (subtract 127)one of exponent, then

perform 2’s complementaddition

mantissas

exponents

alreadynormalized

14 bits

Page 5: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

DivisionDivision

Do unsigned division of the Do unsigned division of the mantissasmantissas

Subtract the exponent of the divisor Subtract the exponent of the divisor from the exponent of the dividendfrom the exponent of the dividend

Normalize the resultNormalize the result Set the sign bit of the resultSet the sign bit of the result

Page 6: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

Setting the sign bit of Setting the sign bit of the quotientthe quotient

The sign bit of the quotient is set The sign bit of the quotient is set usingusing

the following table:the following table:sign bit of

xsign bit of

ysign bit of

x/y

0 0 0

1 0 1

0 1 1

1 1 0

Page 7: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

RoundingRounding

In floating point operations, some In floating point operations, some results may not be representable.results may not be representable.

There is always a small amount of There is always a small amount of error incurred during rounding.error incurred during rounding. Error tend to accumulate over timeError tend to accumulate over time Operations performed in a different Operations performed in a different

order might give different resultsorder might give different results Exact comparison of two floating point Exact comparison of two floating point

variables is infeasiblevariables is infeasible

Page 8: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

Example 13.1Example 13.1

Suppose x = -1.5Suppose x = -1.51010 x 10 x 103838, y = 1.5, y = 1.51010 x 10 x 103838 and z = 1.0 and suppose these are and z = 1.0 and suppose these are single-precision numbers.single-precision numbers.

x+(y+z)= -1.5x+(y+z)= -1.510 10 x 10x 103838 +(1.5 +(1.51010 x 10 x 1038 38 + 1.0)+ 1.0)

= -1.5= -1.510 10 x 10x 103838 + 1.5 + 1.51010 x 10 x 103838 = = 0.00.0

(x+y)+z= (-1.5(x+y)+z= (-1.510 10 x 10x 103838 + 1.5 + 1.51010 x 10 x 1038) 38) + 1.0+ 1.0

= 0 + 1.0 = = 0 + 1.0 = 1.01.0Floating point addition is not associative.

Page 9: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

Rounding RulesRounding Rules Round to nearestRound to nearest. Same as taught in school. . Same as taught in school.

In case of tie, if the lsb is 1 add a 1; if the lsb is In case of tie, if the lsb is 1 add a 1; if the lsb is a 0 truncate. The lsb is always a 0 truncate. The lsb is always 00..

Round toward zeroRound toward zero. Truncate the magnitude . Truncate the magnitude to the correct number of bits.to the correct number of bits.

Round toward positive infinityRound toward positive infinity. The least . The least positive value representable that is not positive value representable that is not arithmetically less than the unrounded value is arithmetically less than the unrounded value is chosen.chosen.

Round toward negative infinityRound toward negative infinity. The least . The least negative value representable but not negative value representable but not arithmetically greater than the unrounded value arithmetically greater than the unrounded value is chosen.is chosen.

Page 10: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

OverflowOverflow

Overflow occurs when the exponent Overflow occurs when the exponent of the normalized result is outside of the normalized result is outside the range of values representablethe range of values representable

The smallest number that can be The smallest number that can be represented normally has an represented normally has an exponent of exponent of

e = -126e = -126, i.e. , i.e. E = 1 = 0000 0001 E = 1 = 0000 0001 and and the largest number has an exponent the largest number has an exponent ofof e = 127, e = 127, i.e.i.e. E = 254 = 1111 1110 E = 254 = 1111 1110

Page 11: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

The IEEE FPS assigns special The IEEE FPS assigns special meaning for extreme values of the meaning for extreme values of the exponentexponent

-- (S=1,E=255,F=0) (S=1,E=255,F=0) ++(S=0,E=255,F=0)(S=0,E=255,F=0) NaN (E=255,F NaN (E=255,F 0)0) 0 (E=0,F=0)0 (E=0,F=0)

Page 12: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

UnderflowUnderflow

Underflow occurs when the result is Underflow occurs when the result is too close to zero to be representedtoo close to zero to be represented

Repeatedly dividing a number by a Repeatedly dividing a number by a positive constant results in values positive constant results in values that will approach zero but may that will approach zero but may never be zero, e.g. 1 divide by 10 never be zero, e.g. 1 divide by 10 repetitivelyrepetitively

In these cases, floating point In these cases, floating point operations after some iteration will operations after some iteration will eventually return zeroeventually return zero

Page 13: 1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication

Until underflow occurs, the Until underflow occurs, the computation is reversible, i.e. if we computation is reversible, i.e. if we multiply the current result by the multiply the current result by the constant the same number of times constant the same number of times we have divided it, it will return the we have divided it, it will return the original numberoriginal number

Once, underflow occurs any number Once, underflow occurs any number of multiplication will still produce of multiplication will still produce zerozero