Numeric Weirdness. Weirdness Overflow Each data type has a limited range – Depends on platform/compiler Going past boundary wraps around.

Slides:



Advertisements
Similar presentations
Computer Organization and Architecture Tutorial 6 Kenneth Lee.
Advertisements

1 C Fundamentals - I Math 130 Lecture # 2 B Smith: Sp05: With discussion on labs, this took 53 minutes. Score 3. Many caveats. B Smith: Sp05: With discussion.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer?
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
Major Numeric Data Types Unsigned Integers Signed Integer Alphanumeric Data – ASCII & UNICODE Floating Point Numbers.
Assembly Language and Computer Architecture Using C++ and Java
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
CS Jan 2007 Chapter 3: sections Variable initialization Variables may be initialized when declared –Form; type name = initial_value; –Example:
1 Error Analysis Part 1 The Basics. 2 Key Concepts Analytical vs. numerical Methods Representation of floating-point numbers Concept of significant digits.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
Computer Science 210 Computer Organization Floating Point Representation.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Simple Data Type Representation and conversion of numbers
IT 251 Computer Organization and Architecture Introduction to Floating Point Numbers Chia-Chi Teng.
Ch. 2 Floating Point Numbers
Information Representation (Level ISA3) Floating point numbers.
Factional Values What is 0.75 in binary?. How could we represent fractions? In decimal: – As fractions : 1/5.
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
Review CAS CS210 Ying Ye Boston University. Logical expressions Truth table input: A, B, Coutput: D ABCD (~A)(~B)(~C)
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Computer Architecture
COMP 116: Introduction to Scientific Programming Lecture 28: Data types.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
S. Rawat I.I.T. Kanpur. Floating-point representation IEEE numbers are stored using a kind of scientific notation. ± mantissa * 2 exponent We can represent.
Floating Point Numbers Expressions Scanner Input Algorithms to Programs Shirley Moore CS 1401 Spring 2013 February 12, 2013.
ITEC 1011 Introduction to Information Technologies 4. Floating Point Numbers Chapt. 5.
Prerequisite Skills VOCABULARY CHECK
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
Integer & Floating Point Representations CDA 3101 Discussion Session 05.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
CSPP58001 Floating Point Numbers. CSPP58001 Floating vs. fixed point Floating point refers to a binary decimal representation where there is not a fixed.
Copyright © – Curt Hill Types What they do.
Floating Point in Binary 1.Place Value Chart:
CEC 220 Digital Circuit Design Binary Codes
Monday, January 14 Homework #1 is posted on the website Homework #1 is posted on the website Due before class, Jan. 16 Due before class, Jan. 16.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Floating Point Numbers
Ch. 10 Numerical Calculations From Valvano’s text Introduction to Embedded Systems.
Number Representation and Arithmetic Circuits
Numbers in Computers.
CEC 220 Digital Circuit Design Binary Codes Mon, Aug 31 CEC 220 Digital Circuit Design Slide 1 of 14.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
FLOATING-POINT NUMBER REPRESENTATION
CHAPTER 5: Representing Numerical Data
CSE 220 – C Programming Bitwise Operators.
Computer Science 210 Computer Organization
Computer Architecture & Operations I
Chapter 4 – Fundamental Data Types
Chapter 6: Data Types Lectures # 10.
ECE Application Programming
Numbers in a Computer Unsigned integers Signed magnitude
EPSII 59:006 Spring 2004.
CS1010 Programming Methodology
Data Structures Mohammed Thajeel To the second year students
What to bring: iCard, pens/pencils (They provide the scratch paper)
Chapter 2 Bits, Data Types & Operations Integer Representation
CSCI206 - Computer Organization & Programming
If {image} find the Riemann sum with n = 5 correct to 3 decimal places, taking the sample points to be midpoints
Computer Science 210 Computer Organization
Use the Midpoint Rule with n = 10 to approximate the integral
How are negative and rational numbers represented on the computer?
Numbers representations
Numerical Integration
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

Numeric Weirdness

Weirdness

Overflow Each data type has a limited range – Depends on platform/compiler Going past boundary wraps around

Data Types Integral Types NameSizeRange short16 bits–2 15 (-32,768) to 2 15 – 1 (32,767) unsigned short16 bits0 to 2 16 – 1 (65535) int32 bits unsigned int32 bits long32 bitsIn Windows, often 64 bits in Linux long 64 bits−9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 unsigned long long64 bits0 to 18,446,744,073,709,551,615

Floating Point Floating point numbers are ALWAYS approximate = =

Floating Point Floating point numbers are ALWAYS approximate = = = = Where is 0.6?

32 Bit Floating Point IEEE specifies conventions for floating points double representation

Data Types Floating Point Types NameSizeRangeSignificant Digits float32 bit +/ x ~7 double64 bits +/ x ~15 long double 80 bits +/ x ~19

Too many choices!!!! Don't panic When in doubt: – Whole numbers int – Decimal numbers double

Order matters Expressions evaluated in PEMDAS order Type rule: – Two ints : int answer – At least one decimal : decimal answer (1.0 / 2) + 1 (0.5) (1 / 2) + 1 (0) + 1 1

^ ^ is not exponentiation Binary XOR 3 = = 0010 XOR = 0001

Powers pow function – In library Must include!!! – Input: base, exponent – Output: answer – always a decimal value (double)

Powers double x = pow(4, 3); //x = 64 double x = pow(2.5, 2); //x = 5.25 double x = pow(9, 0.5); //x = 3.0