SlideServe
Menu
Préférences
© SlideServe · v2026

Floating Point Numbers Expressions Scanner Input Algorithms to Programs

valora avatar
10 diapositives · 258 Views · Aug 08, 2014

This content covers the fundamental concepts of floating point numbers in computer science, particularly in Java programming. It explains how floating point numbers are represented in 32-bit and 64-bit formats, along with the concepts of range and precision. The material includes examples of roundoff errors, expression evaluation, and practical implementation using the Java Scanner class for user input. Additionally, it features algorithms for solving simple programming problems, including calculating the volume of a cylinder, enhancing your understanding of input, processing, and output in programming.

Floating Point Numbers Expressions Scanner Input Algorithms to Programs - slide 1
01 / 10Floating Point Numbers Expressions Scanner Input Algorithms to Programs
1 / 17

Télécharger la présentation

Floating Point Numbers Expressions Scanner Input Algorithms to Programs
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Floating Point NumbersExpressionsScanner InputAlgorithms to Programs Shirley Moore CS 1401 Spring 2013 February 12, 2013

  2. 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

  3. 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 • http://cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htm

  4. Roundoff Error Examples • Try the following in Dr. Java Interactions: > 1.0 - .9 0.09999999999999998 > 1.0 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 0.5000000000000001 > intd = 2147483647 > float e = (float) d > d 2147483647 > e 2.14748365E9 > e = e - 2147483646 0.0 > d = d - 2147483646 1 > d = (int) e 0

  5. Floating Point Number Representation • IEEE Standard 754 Floating Point Numbers • http://steve.hollasch.net/cgindex/coding/ieeefloat.html • What types of errors are the following? > float f = (float) Math.pow(10,38) > f 1.0E38 > intg = (int) f > g 2147483647 > float h = (float) Math.pow(10,39) > h Infinity > float p = (float) Math.pow(10,-50) > p 0.0 • Decimal to floating point converter • http://www.binaryconvert.com/convert_double.html

  6. 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 • 3 + .100000000 * .10000000 - 3. • Did you get the results you expected?

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

  8. Programming Exercise • Now let’s try a complete program: Problem 2.2, page 75. 2.2 (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

  9. Algorithm for Problem 2.2

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