Docsity

Floating Point Representation - Numerical Methods - Lecture Slides, Slides of Mathematical Methods for Numerical Analysis and Optimization

Partial preview of the text

Download Floating Point Representation - Numerical Methods - Lecture Slides and more Slides Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Floating Point Representation

Floating Decimal Point : Scientific Form

  1. 78 is written as 2 .5678 10
  2. 003678 is written as 3. 678 10
  3. 78 is written as 2. 5678 10 − − ×
  • ×
  • ×

Floating Point Format for Binary Numbers ( ) m [( ) m ( ) ] y m

e

mantissa 1 10 sign of number 0 for ve, 1 for -ve 2 = < < = + = × × σ σ

1 is not stored as it is always given to be 1.

e = integer exponent

Example ( ) ( ) ( ) ( ) ( ) 2 2 5 10 2 2

≅ ×

= = ×

9 bit-hypothetical word the first bit is used for the sign of the number, the second bit for the sign of the exponent, the next four bits for the mantissa, and the next three bits for the exponent We have the representation as 0 0 1 0 1 1 1 0 1 Sign of the number mantissa Sign of the exponent exponent

Example

Ten bit word

Sign of number

Sign of exponent

Next four bits for exponent

Next four bits for mantissa

4

  1. 0625 1 2 − ∈ = − = mach Next number ( ) 10 = 1 ( ) ( ) 2 10 = 1. 0001 = 1. 0625

Relative Error and Machine Epsilon

The absolute relative true error in representing

a number will be less then the machine epsilon

Example

( 0110 ) 2 2 5 10 2

− −

= ×
≅ ×

10 bit word (sign, sign of exponent, 4 for exponent, 4 for mantissa) 0 1 0 1 1 0 1 1 0 0 ( ) ( )

  1. 034472 2 0. 0625
  2. 02832
  3. 02832 0. 0274375
  4. 1100 2 0. 0274375 4 0110 2 2 = < = − ∈ = × = − − a Sign of the number Sign of the^ mantissa exponent exponent

IEEE-754 Floating Point Standard

  • Standardizes representation of floating point numbers on different computers in single and double precision.
  • Standardizes representation of floating point operations on different computers.

One Great Reference What every computer scientist (and even if you are not) should know about floating point arithmetic! http://www.validlab.com/goldberg/paper.pdf

13 Example# ( ) ( )

Value 1 1. 2

= − × ×

s e

m ( ) ( )

2 1 1. 10100000 2

= − × × ( ) ( )

1 1. 625 2

= − × × ( ) ( )

= − 1 × 1. 625 × 2 = − 5. 5834 × 10

Sign

(s)

Biased

Exponent (e’)

Mantissa (m)

Docsity.com

14 Example# ????????????????????????????????

Sign

(s)

Biased

Exponent (e’)

Mantissa (m)

Represent -5.5834x

as a single precision floating point number. ( ) ( ) 10 1?

  1. 5834 10 1 1 .? 2 ± − × = − × × Docsity.com

Exponent for Special Cases e ′ e

Actual range of

1 ≤ e ′ ≤ 254 e ′ = 0 and^ e ′ = 255 are reserved for special numbers

Actual range of

− 126 ≤ e ≤ 127

Special Exponents and Numbers ∞ e ′ = 0 all zeros e ′ = 255 all ones s m Represents 0 all zeros all zeros 0 1 all zeros all zeros - 0 all ones all zeros 1 all ones all zeros 0 or 1 all ones non-zero NaN e ′