Modified from Sharon Guffy

Slides:



Advertisements
Similar presentations
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Advertisements

Floating Point Numbers
1 IEEE Floating Point Revision Guide for Phase Test Week 5.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
22-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
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.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Exponents Scientific Notation
IT 251 Computer Organization and Architecture Introduction to Floating Point Numbers Chia-Chi Teng.
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Computer Science 111 Fundamentals of Programming I Number Systems.
IT253: Computer Organization
Data Types and Flow Control June 25, Didn’t we learn this already? Most of these topics have been introduced, but this lecture gives you the details.
Computing Systems Basic arithmetic for computers.
Why does it matter how data is stored on a computer? Example: Perform each of the following calculations in your head. a = 4/3 b = a – 1 c = 3*b e = 1.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Floating Point Numbers
Introduction to Numerical Analysis I
Floating Point Representations
Department of Computer Science Georgia State University
Computer Science 210 Computer Organization
A brief comparison of integer and double representation
Data Representation Binary Numbers Binary Addition
Lecture 9: Floating Point
Chapter 4 – Fundamental Data Types
Chapter 6: Data Types Lectures # 10.
Floating Point Numbers: x 10-18
Chapter 3 Data Storage.
Exponents Scientific Notation
CS 232: Computer Architecture II
Floating-Point and High-Level Languages
IEEE floating point format
April 2006 Saeid Nooshabadi
William Stallings Computer Organization and Architecture 7th Edition
Chapter 6 Floating Point
Arithmetic for Computers
Data Structures Mohammed Thajeel To the second year students
Topic 3d Representation of Real Numbers
Fundamental Data Types
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)
Chapter 2 Bits, Data Types & Operations Integer Representation
Number Representations
Fundamentals of Programming I Number Systems
Computer Science 210 Computer Organization
Approximations and Round-Off Errors Chapter 3
ECEG-3202 Computer Architecture and Organization
Data Types and Variables Part A – Introduction Numeric Data Types
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
Data Types and Data Structures
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Chapter 8 Computer Arithmetic
Fundamental Data Types
Floating Point Numbers
Topic 3d Representation of Real Numbers
Floating Point Numbers
Floating Point Binary Part 1
Number Representations
Section 6 Primitive Data Types
Presentation transcript:

Modified from Sharon Guffy Data Types June 23, 2016 Amy Allen Modified from Sharon Guffy

Data Types Overview Primitive data types Data structures Integers Floating point numbers Boolean Characters Data structures Primitive types = data types (aka numeric types and characters) Aggregate types: ordered or unordered Brief discussion of how to make your own data types in some languages

Integers Number with no fractional part Stores the exact value, so == comparisons are safe Storage: one bit to indicate if the number is positive or negative a binary representation of the number Absolute size limit (system-dependent) E.g. a 32-bit system could store integers within ± (231 - 1) Converting floating point numbers to integers truncates the decimal part (2.9 2, -2.1  -2) Exact storage of the data, but this comes with a size limit Relatively large (aka, 32 bit system has 31 bits to store the integer, 1 bit to store positive vs negative) If you convert a number from float to integer, it will NOT ROUND, just truncates

Special types of integers Long integers Take up more space in memory than integers, but can store larger values Short integers Take up less space, but have smaller range Unsigned integers Same amount of space as integers Only store integers >= 0 Useful for values that can never be negative (count, class size, etc.) Can adjust the size limits of integers Benefits/pitfalls to each size Don’t want to store a small integer with a ton of space Need to remember that a negative number should only be stored as a negative (otherwise problems can arise)

Integer Overflow Overflow: Integer exceeds its maximum/minimum size Different systems deal with overflow differently Some systems (e.g. R) may give you an overflow error In other cases, values may wrap: <largest possible positive integer> + 1 = <largest possible negative integer> Others (e.g. Python) automatically convert to a long integer How do these details affect you?? If size of integer is larger than limit: best thing to happen is an error. Worst thing to happen is a wrap-around The computer doesn’t know what to do. Basically goes to the top limit and then retarts at the bottom (negative) limit Language specificity with how the computer deals with problems Example: Storing a positive (12) or negative (-12) as an UNSIGNED integer Watch out for the giant number in place of the size that you expected

Floating point numbers Numbers stored in scientific notation: Sign Power of ten Binary representation of fractional part i.e. 10.2 = +1.02*101 Double precision: Uses additional space, so it can store larger numbers and more decimal places These are stored in your computer similar to how it is in scientific notation Some number to store the exponent, some number to store the value, some number to store the sign Typically size of storage is set to be muh larger than that of an integer Remember, all restricted by storage size Major problem will be accuracy of number storage. Because computer store everything as binary fraction NOT ALL NUMBERS THAT CAN BE RECORDED IN BASE TEN CAN BE STORED IN BINARY Type Smallest Positive Value Largest Value Precision float 1.17549⨉10-38 3.40282⨉1038 6 digits double 2.22507⨉10-308 1.79769⨉10308 15 digits

Special floating point numbers Special values Inf (infinity) and –Inf (negative infinity) NaN (not a number)—produced from operations without a definite answer (Inf/Inf, etc.)

Problems with floating point numbers Since floating point numbers are stored as fractions in binary, not all numbers can be stored precisely, so math may not give exactly the answer you expect: >>> x = 3.2 >>> y = 1.1 >>> x+y == 4.3 False Hmmmm, that’s not right . . . >>> x+y 4.300000000000001 Therefore, it is best not to check equality of floating point numbers. Think about storing 1/3 as a decimal. .333333x3 = .999999 NOT 1.0 as it should be Remember the restrictions of the tools and rules of your language and number system

Boolean Used to store true/false values Can be converted from any other type. False values (may vary by language): Numeric types: 0 Empty aggregate types ([], “”, {}, etc.) All other values are true Commonly used in loops and control structure This is what your computer loves to store: 1 or 0, yes or no, on or off Almost anything can be sored as a Boolean value How the computer sees it False: nothing, none, 0 True: something

Characters and Strings Think of characters and strings and none numeric. A character is a single symbol and a string multiple symbols strung together Differs significantly in Python and R In Python characters are a string of length one In R strings are still considered under character class

Data Structures Overview A particular way of organizing data in a computer so that it can be used efficiently Range from very basic to very complicated Can be as simple as an ordered list of numbers Can be more complicated like a graph

Why is all of this important? You want to make sure you are storing and accessing your data as efficiently as possible. You need to understand the pit falls of the data types and data structures you’re using so you can trouble shoot errors.