Floating Point Numbers Expressions Scanner Input Algorithms to Programs Shirley Moore CS 1401 Spring 2013 February 12, 2013.

Slides:



Advertisements
Similar presentations
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Advertisements

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Faculty of Computer Science © 2006 CMPUT 229 Floating Point Representation Operating with Real Numbers.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Numerical Data Recitation – 01/30/2009
Floating Point Numbers
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.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Computer Science 210 Computer Organization Floating Point Representation.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Selection and Testing Shirley Moore CS 1401 Spring 2013 February 21 and 26,
Computer Programming Lab(4).
Using Java's Math & Scanner class. Java's Mathematical functions (methods) (1)
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Computer Programming Lab(5).
Convert Decimal to Floating point number [IEEE 754]
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Simple Data Type Representation and conversion of numbers
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Computer Science 101 Introduction to Programming.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
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.
Quick and Easy Binary to dB Conversion George Weistroffer, Jeremy Cooper, and Jerry Tucker Electrical and Computer Engineering Virginia Commonwealth University.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Floating Point Representation.
Number Representation, Data Types and Elementary Programming Shirley Moore CS 1401 February 5-7, 2013.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Numeric Weirdness. Weirdness Overflow Each data type has a limited range – Depends on platform/compiler Going past boundary wraps around.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Java Variables, Types, and Math Getting Started Complete and Turn in Address/Poem.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Ch. 10 Numerical Calculations From Valvano’s text Introduction to Embedded Systems.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
Iterative Structures (Loops) CS 1401 Spring 2013 Shirley Moore, Instructor February 28, 2013.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Lecture 6: Floating Point Number Representation Information Representation: Floating Point Number Representation Lecture # 7.
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
CS 201 Lecture 2: Elementary Programming Tarik Booker CS 201 California State University, Los Angeles.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
CSCI206 - Computer Organization & Programming
Introduction to Numerical Analysis I
Topic 2 Elementary Programming
Dr. Clincy Professor of CS
Introduction To Computer Science
Floating Point Representations
Dr. Clincy Professor of CS
Chapter 4 – Fundamental Data Types
EPSII 59:006 Spring 2004.
Data types, Expressions and assignment, Input from User
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
CSCI206 - Computer Organization & Programming
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Dr. Clincy Professor of CS
Java Variables, Types, and Math Getting Started
Dr. Clincy Professor of CS
Fundamentals 2.
CS 200 Primitives and Expressions
CS2011 Introduction to Programming I Elementary Programming
Java Programming Loops
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
Mathematical Preliminaries
Lecture 37 – Practice Exercises 9
Lecture 37 – Practice Exercises 9
Presentation transcript:

Floating Point Numbers Expressions Scanner Input Algorithms to Programs Shirley Moore CS 1401 Spring 2013 February 12, 2013

Learning Outcomes Explain how floating point numbers are represented inside a computer Define what is meant by range and precision of a floating point number representation Define roundoff error and explain how it can accumulate to produce results with significant errors Evaluate expressions using operator precedence rules Use the Java Scanner class to obtain user keyboard input Solve simple IPO (Input-Processing-Output) programming problems by – Writing a step-by-step algorithm – Implementing the algorithm in Java – Verifying correct output

Real vs. Floating Point Numbers How many real numbers are there between 0 and 1? Floating point numbers can be represented in 32 bits (single precision) or 64 bits (double precision). – How many floating point numbers can we represent in 32 bits? – How many floating point numbers can we represent in 64 bits? How can we represent 0.5 in binary? How can we represent 1/3 as a decimal fraction? How can we represent 0.1 in binary? Converting decimal fractions to binary – htm htm

Roundoff Error Examples Try the following in Dr. Java Interactions: > > > int d = > float e = (float) d > d > e E9 > e = e > d = d > d = (int) e 0

Floating Point Number Representation IEEE Standard 754 Floating Point Numbers – What types of errors are the following? > float f = (float) Math.pow(10,38) > f 1.0E38 > int g = (int) f > g > float h = (float) Math.pow(10,39) > h Infinity > float p = (float) Math.pow(10,-50) > p 0.0 Decimal to floating point converter –

Expression Evaluation In the Dr Java Interactions window, try evaluating the following expressions:  5/3  5 % 3  5./3.  5 / 0  5./0.  5 < 6  5. < 6.  3 – 2*5  (3 - 2)*5  * Did you get the results you expected?

Scanner Class In the Dr. Java Interactions window type the following  Scanner input = new Scanner(System.in);  System.out.println(“Enter an integer: “);  int n = input.nextInt();  n  System.out.println(“Enter a real number: “);  double r = input.nextDouble();  r

Programming Exercise Now let’s try a complete program: Problem 2.2, page (Compute the volume of a cylinder) Write a program that reads in the radius and length of a cylinder and computes the area of the base and the volume of the cylinder using the following formulas: area = π * radius * radius volume = area * length

Algorithm for Problem 2.2

Lab 3 – Projectile Motion By Thursday – Problem description – Algorithm – Set of test cases