Docsity

Floating Point Arithmetic in Math/CS 375: Understanding IEEE Standard and Implications, Study notes of Computer Science

Partial preview of the text

Download Floating Point Arithmetic in Math/CS 375: Understanding IEEE Standard and Implications and more Study notes Computer Science in PDF only on Docsity!

Math/CS 375

Spring 2009

Lecture 1f Introduction to Matlab:

Floating Point Arithmetic

Chapter 0

Floating-Point Numbers

  • Nearly all computation on a digital computer is

done in floating-point (FP) arithmetic.

  • A floating-point number system is a number

system that uses a finite number of digits to represent the real number system that we use in exact computation.

  • Floating-point numbers are generally repres-

ented in binary in a computer.

sign bit

mantissa (52 bits)

(it is assumed d1= 1, so only need d2,…d53)

exponent (11 bits)

Machine epsilon

  • Is the distance from 1 to the next larger float-

pointing number,

  • The relative error in representing a nonzero real

number, x, in the system F is

t

eps

1

 : b

x

x fl x

(RELATIVE) ROUNDOFF ERROR

MATLAB DP Floating Point

Every computation produces a floating point number.

  • Matlab stores floating point numbers and carries out elementary operations to an accuracy of about 16 significant decimal digits.
  • If the result is larger than realmax = 1.7977*10^(+308), overflow occurs and the result is Inf ;
  • If the result is smaller than realmin = 2.2225*10^(-308), underflow occurs, and the result is – Inf or 0.
  • A computation whose result is not mathematically defined produces NaN (Not a Number).

Arithmetic Operator Precedence

Precedence Operator

1 (highest) Exponentiation (^)

2 Unary plus (+), unary minus (-)

3 Multiplication (*), division (/)

4 (lowest) Addition (+), subtraction (-)

Format Example ()

» format long (default for  )

pi = 3.

» format short

pi = 3.

» format short e

pi = 3.1416e+

» format long e

pi = 3.141592653589793e+

Some Interesting Implications of

Rounding Error

Three of these examples follow:

  • The Patriot
  • Down and out in Vancouver
  • I shot an arrow in the air (The sad story

of the Ariane 5)

The Patriot (cont.)

  • To compute the interval, timer values were converted to floating-point representation by multiplying by 0.1.
  • 0.1 has a non-terminating binary expansion; consequently, the interval was computed with error - the larger the value, the larger the error.
  • At the time of the incident, the missile battery had been operating for over 100 hrs, resulting in an error of 0.34 sec in the timer causing the system to look in the wrong place for the incoming Scud.

Down and Out in Vancouver

Stock Exchange

  • In 1982 the Vancouver Stock Exchange

introduced an index with a nominal value of 1000.000.

  • After each transaction, the index was

recomputed and truncated to three decimal places.

  • After 22 months of transactions, the index was

524.881.

  • The true value was 1098.811.

The sad story of the Ariane 5

  • The IRS tried to convert a 64-bit floating

point number to a 16-bit integer.

  • The number was too large, which triggered

an error and send a diagnostic message to

the On-Board Computer.

  • The OBC interpreted the diagnostic word

as flight data.

  • Finis!

Solution of a Quadratic

Equation

The solution to the quadratic equation

x^2 +bx + c = 0*

is

x = [-b +/-sqrt(b^2 – 4c)]/*

Example: b = -0.125335, c = +0.360551e-6,

using 6-digit decimal arithmetic

r1 = 1.25333e-1 (1.253321232e-1)

r2 = 2.50000e-6 (2.876764477e-6)

Quadratic Equation: the cure

  • We must restore the information that we don’t

have about the coefficient c.

  • A little algebra will tell us that if r1 and r1 are

real, distinct roots of x^2 + bx + c = 0* , then r1r2 = c*

  • So, we compute r1 as before and compute r2 as

r2 = c/r1 = 3.60551e-6 / 1.25332e-

= 2.87677 (2.876764477e-6)

COMPLEX NUMBERS

  • z = x + i*y
  • x = Re(z) is the real part
  • y = Im(z) is the imaginary part
  • i^2 = -1 is the imaginary unit
  • polar form
  • complex conjugate

   

z e cos i sin

i   

zxiy