Docsity

MATLAB ME123 winter 2017, Study notes of Engineering

Toggle sidebar
bg1
ME123ComputerApplicationsI
Day 32
• Computer representation of integers
• Integer equality checks succeed
• Representation of floating point numbers
• Floating point equality checks fail
• Finding floating point values
• Max and min
• (Exercises)
ME123ComputerApplicationsI
Computer Representation of Integers
Integers are stored exactly in the computer.
Uses binary
Sequence of 1’s and 0’s (on and off)
0b0001 = 1 in decimal
0b0010 = 2 in decimal
0b0011 = 3 in decimal
pf3
pf4
pf5

Partial preview of the text

Download MATLAB ME123 winter 2017 and more Study notes Engineering in PDF only on Docsity!

ME123 Computer Applications I

Day 32

• Computer representation of integers

• Integer equality checks succeed

• Representation of floating point numbers

• Floating point equality checks fail

• Finding floating point values

• Max and min

• (Exercises)

Computer Representation of Integers

Integers are stored exactly in the computer.

Uses binary

Sequence of 1’s and 0’s (on and off)

0b0001 = 1 in decimal

0b0010 = 2 in decimal

0b0011 = 3 in decimal

ME123 Computer Applications I

Computer Representation of Integers

You don’t need to know how binary works, just

that it is exact for integers.

You will learn more about this later in your ME

curriculum.

Integer Equality Checks Succeed

Because integers are stored exactly, checking

for equality works fine.

ME123 Computer Applications I

Floating Point Equality Checks Fail

The equality check with floating point doesn’t

work:

Nothing prints!

Floating Point Equality Checks Fail

Actually, the equality check works

occasionally, depending on the number:

ME123 Computer Applications I

Finding Floating Point Values

We use a tolerance (range) to locate floating

point values:

Small tolerance

Value to find

Finding Floating Point Values

This code is a bit simpler but does the same

thing: