Understanding Number Representation and Precision in Computing for Engineers, Study notes of Computer Science

An introduction to number representation in computing for engineers, including precision and accuracy considerations. Topics covered include binary, integer, and real number representation, as well as limitations and standards. Students are encouraged to explore online resources for further learning.

Typology: Study notes

Pre 2010

Uploaded on 08/04/2009

koofers-user-vr5
koofers-user-vr5 🇺🇸

10 documents

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS1371
Introduction to Computing
for Engineers
Numbers and Arrays
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Understanding Number Representation and Precision in Computing for Engineers and more Study notes Computer Science in PDF only on Docsity!

1

CS1371 Introduction to Computing for Engineers Numbers and Arrays

How are Numbers Represented? Numeric representation is a key part of defining dataused in a computer program. We will consider severaltopics: • Limitations in representation when using finite sizednumbers (precision & accuracy) • Binary representation • Integers versus real numbers 4

(aka: fixed vs floating point numbers)IEEE Floating PointHow Matlab handles this

Numbers: Precision and Accuracy Good Accuracy^ Good PrecisionGood Precision^ Poor Accuracy 5

Good Accuracy^ Poor Precision

Poor Accuracy Poor Precision

-^ Low precision:

π^ = 3.

-^ High precision:

π^ = 3.

-^ Low accuracy:

π^ = 3.

-^ High accuracy:

π^ = 3.

-^ High accuracy & precision:

π^ = 3. In most cases, computers must deal with finite precision(some software provides unlimited precision).

Inside the Bytes

-^ A byte is the smallest memory allocation available. •^ A byte contains 8 bits so that:^ – Smallest: 0 0 0 0 0 0 0 0 = 0 7

10

  • Largest:^ 1 1 1 1 1 1 1 1 =^7 6 5 _12+12+12_^ _+1_

_4 32 1 +12+12+12+1_**

0 8 = 255(or 2^ -1)^10

-^ Result: a single byte can be used to store an integer numberranging from 0 to 255

(256 different numbers)

-^ If negative numbers are included, one bit must be dedicated to thesign, leaving only 7 bits for the number^ – Smallest: 0^ – Largest: +

or -128^10

Signed-Magnitude

(OPTIONAL MATERIAL)

•^ Example of signed magnitude:^ „^^00000101 8

•^ Notice also that signed-magnitude gives plus and minuszero!^ –^^00000000

Two’s Complement

(OPTIONAL MATERIAL)

-^ Two’s Complement has no negative zero; for a onebyte integer:^ –^ 01111111 = 127,^ –^ 00000001 = 1,^ –^ 00000000 = 0,^ –^ 11111111 = - 1,^ –^ 10000000 = -128 •^ Range: [ -128, 127 ] 10

Inside the Bytes: Integers 8 • 2 -1 (255) is not a very big number, so computers generally usemultiple bytes to represent numbers: • Integers are defined in various sizes: 11

Other languagesuse differentnames! Size^ Precision

Matlab^

Java (^8) 1 byte 2 = 256 uint8, int*^

byte 2 byte^ 65,

uint16, int*

short 4 byte^ 4,294,967,

uint32, int*^

int (^64) 8 byte 2 --^ long

  • Matlab uint’s are “unsigned integers” (no sign bit; positive values only) Note: A word is the basic size of the CPU registers and for Pentium chips it is 4 bytes or 32 bits; it is 8 bytes for the new Itanium and some unix chipsets. It was 2 bytes for early Intel chips; some new game consoles use 16 byte words.

Inside the Bytes: Real Numbers • Matlab’s real is called double and is an 8 byte IEEE 754 format. • Because only a finite number of bits are used for each part of thenumber, not all possible real numbers can be represented in acomputer using IEEE 754 13

(^0) Positive numbers smaller than 2

  • ( positive underflow, Matlab “realmin”

) Positive numbers greater-52^1023 than (2-2) x 2^ ( positive overflow, Matlab“realmax” ) Negative numbers less than -(2-

-52^1023 ) x 2^ Negative numbers-1022greater than -2^ ( negative underflow ( negative overflow ) )

Zero^ (actually is a specialcombination of bits) RESULT : about 16 digits of precision in the range ±

±

Inside the Bytes

Others sources of error in computation: • Errors in the input data - measurement errors, errors^ introduced by the conversion of decimal data to binary,^ roundoff errors. • Roundoff errors during computation (as discussed) • Truncation errors - using approximate calculation is inevitable^ when computing quantities involving limits and other infinite^ processes on a computer^ – Never try to compare two floating point numbers for equality because all^ 16+ digits would have to match perfectly…^ – Use Matlab routi 14

nes whenever possible (they are optimized to avoid truncation and roundoff^ problems)

  • Representing Numbers Learning OutlineObjectivesPrecision and accuracy Understand howNumbers on a computernumbers areExercisesstored in aSummarycomputer andwhat theimplications are Not in our textbook … pay attention … create your own knowledge base!
  • Memory Allocation in MATLAB

17

What it Means…

-^ In the previous slide, we see: •^ What is the size of the variable “

i”

-^ What does “class

” represent? Name^ • How many bytes are used to store the value? Size^

Bytes^ Class i^ 1x^

8 double^ array s^ 1x^

86 char^ array t^ 1x

1600

double^ array

SUMMARY

-^ Describe memory. List different kinds of memory. •^ What is IEEE 754? Describe how MATLAB representsnumbers. •^ Draw a number line and identify ranges where computerswill generate errors. •^ Describe three potential sources of errors incomputation. •^ Describe precision. Describe accuracy. •^ Describe how we can protect ourselves fromcomputation error. 19

Summary

20

Action Items • Review the lecture • How will you use this informationin your current work? … futurework at GT? • Start Exploring Matlab! • Increment your record ofcommands learned • Come prepared to ask questionsabout MATLAB Lecture Outline • Numbers in the Computer • Precision and Accuracy