Docsity

Understanding Multiplication and Scientific Notation in IEEE 754 - Prof. Leona Mcmillan, Study notes of Computer Architecture and Organization

Partial preview of the text

Download Understanding Multiplication and Scientific Notation in IEEE 754 - Prof. Leona Mcmillan and more Study notes Computer Architecture and Organization in PDF only on Docsity!

10/10/

Floating-Point Arithmetic

Reading: Study Chapter 4.

if ((A + A) - A == A) {SelfDestruct()}

10/10/

Why Floating Point?

Aren’t Integers enough? •^

Many applications require numberswith a VERY large range.(e.g. nanoseconds to centuries)

-^

Most scientific applications need real numbers (e.g.

ππππ

But so far we have only used integers. •^

We COULD use integers with a fixed “binary” point

-^

We COULD implement fractions using two integers(e.g.

•^

Floating point is a better answer for most applications.

10/10/

Multiplication in Scientific Notation

•^

Is straightforward:^ –

Multiply together the significant parts – Add the exponents – Normalize if required

-^

Examples:

1024

x^

10

3

x 0.

x^

10

64

x 10

1

42

x^

10

1

x 0.

x^

10

x^

10

x^

10

0 (Normalized)

In multiplication, howfar is the most you willever normalize?

In addition?

10/10/

FP == “Binary” Scientific Notation

•^

IEEE single precision floating-point format

0x42280000 in hexadecimal

•^

Exponent: Unsigned “Bias 127” 8-bit integer

E = Exponent + 127 Exponent = 10000100 (132) – 127 = 5

•^

Significand: Unsigned fixed binary point with “hidden-one”

Significand = “1”+ 0.01010000000000000000000 = 1.

•^

Putting it all together

N = -

S^ (1 + F ) x 2

E-

= -

0 (1.3125) x 2

5 = 42

0 (^01) 0 0 0 (^01)

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

(^01) 0 1 0

0

“F”

Significand (Mantissa) - 1

“E” Exponent + 127 “S”SignBit

L12 – Multiplication 7

10/10/

Zeros

-^

How do you represent 0?

-^

Zero

Sign = ?, Exponent = ?, Significand =?

–^

Here’s where the hidden “1” comes back to bite you

-^

Hint: Zero is small. What’s the smallest number youcan generate?

-^

E = Exponent + 127, Exponent = -127, Signficand = 1.

(1.0) x 2

= 5.87747 x 10

  • -^

IEEE Convention^ – When E = 0 (Exponent = -127), we’ll interpret numbers

differently… 0 00000000 00000000000000000000000 = 0 not 1.0 x 2

1 00000000 00000000000000000000000 = -0 not -1.0 x 2

Yes, there are “2” zeros. Setting E=0 is also used to represent a few other small numbersbesides 0. In all of these numbers there is no “hidden” one assumed in F, and they are calledthe “unnormalized numbers”. WARNING: If you rely these values you are skating on thin ice!

L12 – Multiplication 8

10/10/

“Denorm

Gap”

Low-End of the IEEE Spectrum

0

2

2

2

-bias

1-bias

2-bias

normal numbers with hidden bit

The gap between 0 and the next representable normalized number is much larger

than the gaps between nearby representable numbers. IEEE standard uses denormalized numbers to fill in the gap, making the

distances between numbers near 0 more alike. 0

2

2

2

-bias

1-bias

2-bias

p bits ofprecision

p- bits ofprecisionDenormalized numbers have a hidden “0” and a fixed exponent of -126NOTE: Zero is represented using 0 for the exponent and 0 for the mantissa.Either, +0 or -0 can be represented, based on the sign bit.

X = (-1)

2

(0.F)

S^

10/10/

Floating Point Anomalies

It is CRUCIAL for computer scientists to know that

Floating Point arithmetic is NOT the same arithmeticyou learned in grade school! 1.0 is NOT EQUAL to 10*0.1 (Why?)

ex. 1.0 * 10.0 == 10.

but,

0.1 decimal == 1/16 + 1/32 + 1/256 + 1/512 + 1/4096 + … ==

0.0 0011 0011 0011 0011 0011 … Consider, in decimal 1/3 is a repeating fraction 0.333333…If you quit at some fixed number of digits, then 3 * 1/3 != 1

10/10/

F.P.

Real Numbers

•^

Floating point is an approximation of “Real Numbers”;it even breaks basic LAWS of math^ Floating Point arithmetic IS NOT, in general, associative

x + (y + z) is not necessarily equal to (x + y) + z

Thus, the order of calculations matters, and should be considered

-^

Arithmetic is approximate whereas integer arithmetic isexact. Operations may not result in any visible change

(x + 1.0) MAY == x

•^

Floating-point is often

overused

by programmers, since

the “finiteness” of the representation less apparent

-^

Programmers who assume that floating point numbersare real numbers, do so at their peril

10/10/

Floating-Point Addition H/W

L12 – Multiplication 14

10/10/

Floating-Point Multiplication H/W S^

E^

F^

S^

E^

F

×

24 by 24 round

SmallADDER

Mux (Shift Right by 1)

Control

Subtract 127^ Subtract 1

S^

E^

F

Step 1:^ Multiply significandsAdd exponentsE

= ER

  • E 1

-127 2

Exponent

  • 127 =R

Exponent

  • 127 1

  • Exponent

  • 127 2

  • 127 Step 2:^ Normalize result(Result of

[1,2) *[1.2) = [1,4)at most we shiftright one bit, andfix exponent

Surprisingly, FPmultiplication issimpler than FPaddition

10/10/

Chapter Three/Four Summary

Computer arithmetic is constrained by limited precisionBit patterns have no inherent meaning but standards do

exist^ two’s complementIEEE 754 floating point Computer instructions determine “meaning” of the bit

patterns Performance and accuracy are important so there are many

complexities in real machines (i.e., algorithms andimplementation). Numerical computing employs methods that differ from

those of the math you learned in grade school.