Computer Basics Computer Basics IEEE Floats IEEE Floats (Part II) - - PowerPoint PPT Presentation

computer basics computer basics ieee floats ieee floats
SMART_READER_LITE
LIVE PREVIEW

Computer Basics Computer Basics IEEE Floats IEEE Floats (Part II) - - PowerPoint PPT Presentation

Computer Basics Computer Basics IEEE Floats IEEE Floats (Part II) (Part II) Rubin H Landau Rubin H Landau With With Sally Haerer and Scott Clark Sally Haerer and Scott Clark Computational Physics for Undergraduates Computational Physics


slide-1
SLIDE 1

Introductory Computational Science Introductory Computational Science Rubin Landau, EPIC/OSU 2005 Rubin Landau, EPIC/OSU 2005 1 1

Computer Basics IEEE Floats

(Part II)

Computer Basics IEEE Floats

(Part II)

Rubin H Landau Rubin H Landau

With With

Sally Haerer and Scott Clark Sally Haerer and Scott Clark

Computational Physics for Undergraduates Computational Physics for Undergraduates

BS Degree Program: Oregon State University BS Degree Program: Oregon State University

“Engaging People in Cyber Infrastructure Engaging People in Cyber Infrastructure” Suppor Support by EPICS/NSF & OSU by EPICS/NSF & OSU

slide-2
SLIDE 2

Introductory Computational Science Introductory Computational Science Rubin Landau, EPIC/OSU 2005 Rubin Landau, EPIC/OSU 2005 2 2

Model: Machine Precision Model: Machine Precision Model: Machine Precision

 Floating point  limited precision − singles (32b): 6-7 decimal places − doubles 15-16 places − affects calculations: 7 + 10-7 = ?  Different exponents   can't add mantissas  Shift bits (insert 0's) till same exponent − Last digits lost (truncation error) − Ignore 10-7 in single precision 7 = 0 1000 0010 1110 0000 0000 0000 0000 000, 10-7 = 0 0110 0000 1101 0110 1011 1111 1001 010 10-7 = 0 1000 0010 0000 0000 0000 0000 0000 000  7 + 10-7 = 7

slide-3
SLIDE 3

Introductory Computational Science Introductory Computational Science Rubin Landau, EPIC/OSU 2005 Rubin Landau, EPIC/OSU 2005 3 3

``Machine Precision’’ m ``Machine Precision ``Machine Precision’’ ’’  m

m

  • Measure of precision in computation
  • Definition: max # add to 1 gives 1 as answer

1c + m = 1c (1)

x stored on computer:

m  10 -7 (single), m  10 -16 (double)

(2)

xc  x (1  ), | |  m

(3)

  • Scientists: Just say No! to singles
slide-4
SLIDE 4

Introductory Computational Science Introductory Computational Science Rubin Landau, EPIC/OSU 2005 Rubin Landau, EPIC/OSU 2005 4 4

Time for Exercises in Lab Time for Exercises Time for Exercises in Lab in Lab

slide-5
SLIDE 5

Introductory Computational Science Introductory Computational Science Rubin Landau, EPIC/OSU 2005 Rubin Landau, EPIC/OSU 2005 5 5

Landau’s Rules of Education Landau Landau’ ’s Rules of Education s Rules of Education

1.

Most of ed is learning names; ideas simple

2.

Confusion is the first step towards understanding

3.

Traumatic experiences are good teachers

slide-6
SLIDE 6

Introductory Computational Science Introductory Computational Science Rubin Landau, EPIC/OSU 2005 Rubin Landau, EPIC/OSU 2005

Exercise: Determine Your m Exercise: Determine Your Exercise: Determine Your  m

m

  • 1. Determine the machine precision 

m

m of your computer

eps = 1. begin do N times eps = eps/2. // Make smaller

  • ne = 1. + eps

write: loop number, one, eps end do

  • 2. Determine 

m

m for single & double precision (floats)

  • 3. * Determine precise values

(decimal OK, octal, hexadecimal/octal better) Sam ple pseudocode:

Lab 1

slide-7
SLIDE 7

Introductory Computational Science Introductory Computational Science Rubin Landau, EPIC/OSU 2005 Rubin Landau, EPIC/OSU 2005

Exercise: Summing Series Exercise: Summing Series Exercise: Summing Series

  • 1. Calculate e –x : x = 0.1, 1, 10, 100, 1000
  • 2. Require “absolute” error less than 1 part in 108

| term/ sum| < 10-8 Presumptions: remainder ≈ term no roundoff error

Lab 2

e−x ' 1 − x + x2

2! 2! − x3 3! 3! + · · ·

· · · + xN

N!

(sum =) (term)

+ remainder

slide-8
SLIDE 8

Introductory Computational Science Introductory Computational Science Rubin Landau, EPIC/OSU 2005 Rubin Landau, EPIC/OSU 2005

Series Exercise (cont) Series Exercise (cont) Series Exercise (cont)

  • 3. Output as table

x N sum |sum - exp(-x)| /sum

“exp(-x)” = built-in exponential

(Math.exp)

  • 4. Compare “good'' to “bad'' (factorials and powers)

term = 1, sum = 1, eps = 10**(-8) // Initialize do term = -term * x/i // “Good”, factorials “bad” sum = sum + term // Add in term while abs(term/sum) > eps // Continue if error end do

Lab 3

e−x ' 1 − x + x2

2! − x3 3! + · · · + xN N!

(sum =) (term)