Computing Fundamentals

Similar documents
Floating-point representation

2 Computation with Floating-Point Numbers

2 Computation with Floating-Point Numbers

Most nonzero floating-point numbers are normalized. This means they can be expressed as. x = ±(1 + f) 2 e. 0 f < 1

Floating Point Numbers

Floating Point Numbers

ECE232: Hardware Organization and Design

Data Representation Floating Point

Finite arithmetic and error analysis

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

Data Representation Floating Point

Bits, Words, and Integers

Dr Richard Greenaway

Lecture 2 FORTRAN Basics. Lubna Ahmed

Floating-point representations

Floating-point representations

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

Floating-Point Numbers in Digital Computers

Floating-Point Numbers in Digital Computers

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Floating Point January 24, 2008

Representing and Manipulating Floating Points. Jo, Heeseung

FLOATING POINT NUMBERS

Roundoff Errors and Computer Arithmetic

Representing and Manipulating Floating Points

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Floating Point Arithmetic

Mathematical preliminaries and error analysis

Lecture Objectives. Structured Programming & an Introduction to Error. Review the basic good habits of programming

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Floating-Point Arithmetic

Built-in Types of Data

1.2 Round-off Errors and Computer Arithmetic

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Review Questions 26 CHAPTER 1. SCIENTIFIC COMPUTING

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

Scientific Computing: An Introductory Survey

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

Single row numeric functions

CS321. Introduction to Numerical Methods

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5.

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Arithmetic and Logic Blocks

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

CS 33. Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Computational Mathematics: Models, Methods and Analysis. Zhilin Li

A.1 Numbers, Sets and Arithmetic

Numerical computing. How computers store real numbers and the problems that result

Up next. Midterm. Today s lecture. To follow

Foundations of Computer Systems

Floating Point. CSE 238/2038/2138: Systems Programming. Instructor: Fatma CORUT ERGİN. Slides adapted from Bryant & O Hallaron s slides

CS 6210 Fall 2016 Bei Wang. Lecture 4 Floating Point Systems Continued

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Chapter 4. Operations on Data

Julia Calculator ( Introduction)

Computer Arithmetic Floating Point

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

Representing and Manipulating Floating Points

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

LAB 1 General MATLAB Information 1

Classes of Real Numbers 1/2. The Real Line

Floating point numbers in Scilab

Using the um-fpu with the Javelin Stamp

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

System Programming CISC 360. Floating Point September 16, 2008

Introduction to Programming and 4Algorithms Abstract Types. Uwe R. Zimmer - The Australian National University

Representing and Manipulating Floating Points

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Implementation of IEEE754 Floating Point Multiplier

Data Representation Floating Point

Floating Point Numbers

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS429: Computer Organization and Architecture

Logic, Words, and Integers

Basic types and definitions. Chapter 3 of Thompson

Computer Organization: A Programmer's Perspective

Numeric Encodings Prof. James L. Frankel Harvard University

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

On a 64-bit CPU. Size/Range vary by CPU model and Word size.

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

Computational Economics and Finance

Giving credit where credit is due

Choose the correct answer below. 2. Convert the angle to a decimal in degrees.

Giving credit where credit is due

Mentor Graphics Predefined Packages

Scheme Quick Reference

Scientific Computing: An Introductory Survey

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

Floating Point Numbers. Lecture 9 CAP

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

Transcription:

Computing Fundamentals Salvatore Filippone salvatore.filippone@uniroma2.it 2012 2013 (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 1 / 18

Octave basics Octave/Matlab: f p r i n t f ( H e l l o world \n ) ; Octave entities: 1 Numeric constants; 2 Variables; 3 Operators; A variable is fundamentally a tag associated with a memory area: it contains data. A variable name is a sequence of letters and numbers starting with a letter. Assignment operator: one =1; (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 2 / 18

Octave basics DataType: A set of entities and the operations defined on them. Examples of primitive data types: Booleans (logical); Integers; Floating-point; Complex. In Octave/Matlab: distinction among the numerics is blurred. (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 3 / 18

Octave basics Syntactic elements: arithmetic operators + Addition; - Subtraction; * Multiplication; / Division; ^ Exponentiation; (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 4 / 18

Octave basics Syntactic elements: relational operators < Less than; <= Less than or equal to; > Greater than; >= Greater than or equal to; == Equal; ~= Not equal; in Octave (but not in Matlab) also!= (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 5 / 18

Octave basics Syntactic elements: logical operators ~, not NOT; &, &&, and AND;,, or OR; xor Exclusive OR; false true (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 6 / 18

Octave basics SCRIPTS: Sequences of instructions stored in a file, so that they can be retrieved and executed Examples. (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 7 / 18

Octave basics Syntactic elements: functions sqrt Square root; exp Exponential; log, log2, log10 Logarithm; sin, cos, sinh, cosh, tan, asin, acos, atan Trigonometric functions airy, besselj, beta, erf, gamma, legendre Special functions (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 8 / 18

Computer Arithmetic Integers are represented with 8, 16, 32 or 64 bits. Integer operators work as expected, except that the operands must be of the same type. In Octave/Matlab most operations implicitly convert to floating-point. (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 9 / 18

Computer Arithmetic Since computers represent numbers with finite strings of digits (bits), we will never have real numbers; what we can aim for is a (finite) subset of the rationals. Therefore any real number x will be represented by an approximation ˆx = round(x) = x(1 + δ). What we can hope is to somehow control the relative error δ ɛ (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 10 / 18

Floating-Point Arithmetic Floating-point numbers: a subset of the rational numbers with the form (s, e, f ) where s is the sign, e is the exponent and f is the fraction part, or mantissa; we also have parameters β, t e min and e max such that (s, e, f ) = s f β e t = ±β e ( d1 β + d 2 β 2 +... d t β t with f represented on t figures..d 1 d 2... d t ) (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 11 / 18

Floating-Point Arithmetic Floating-point numbers: a subset of the rational numbers with the form (s, e, f ) where s is the sign, e is the exponent and f is the fraction part, or mantissa; we also have parameters β, t e min and e max such that (s, e, f ) = s f β e t = ±β e ( d1 β + d 2 β 2 +... d t β t with f represented on t figures..d 1 d 2... d t Normalized numbers: m β t 1, i.e. d 1 0; we also add explicitly the zero (which would be excluded). ) (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 11 / 18

Floating-Point Arithmetic As an example: with β = 2, t = 3, e min = 1, e max = 3 we can represent the following set of numbers: 0, 0.25, 0.3125, 0.3750, 0.4375, 0.5, 0.625, 0.750, 0.875 1.0, 1.25, 1.50, 1.75, 2.0, 2.5, 3.0, 3.5, 4.0, 5.0, 6.0, 7.0 Note: the relative error decreases within each octave, but the minimum and maximum are the same over all octaves! (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 12 / 18

Floating-Point Arithmetic If β = 2 then d 0 0 d 0 = 1, therefore the first bit can be assumed ( phantom ). (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 13 / 18

Floating-Point Arithmetic If β = 2 then d 0 0 d 0 = 1, therefore the first bit can be assumed ( phantom ). To get a uniform spacing we introduce the so-called denormalized numbers, i.e. numbers with e = e min, d 0 = 0; in our example these are 0.0625, 0.125, 0.1875, and they fill the hole around zero as follows: (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 13 / 18

Floating-Point Arithmetic IEEE 754 Single precision β = 2, t = 23 + 1 ( phantom bit is 1 if normalized, 0 otherwise), e min = 127, e max = 127, u = 6.0 10 8, range 10 ±38 Double precision β = 2, t = 52 + 1 ( phantom bit is 1 if normalized, 0 otherwise), e min = 1023, e max = 1023, u = 1.1 10 16, range 10 ±308 Extended precision β = 2, t = 63 + 1 ( phantom bit is 1 if normalized, 0 otherwise), e min = 16383, e max = 16383, u = 5.4 10 20 Quad precision β = 2, t = 112 + 1 ( phantom bit is 1 if normalized, 0 otherwise), e min = 16383, e max = 16383, u = 9.6 10 35 Octave/Matlab use double precision numbers. (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 14 / 18

Floating-Point Arithmetic IEEE 754 When e = 2047, the actual exponent is 2047 1023 = 1024; with f = 0 this is understood to represent infinity. When f 0, it is a NaN (Not a Number) 1/0 = 1/0 = 0/0 = = / = 0 = 1 = NaN (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 15 / 18

Floating-Point Arithmetic IEEE 754 In general a real number a is not exactly representable. If fl(a) is the best floating point approximation to a, we define the machine precision through the relation fl(a) = a(1 + ɛ), ɛ ɛ M for all a. The quantity ɛ M is closely related to the number of significant digits, but has nothing to do with the smallest represented number. In double precision IEEE arithmetic we have ɛ 10 16 whereas the smallest normalized numer is approx. 10 308, and the smallest unnormalized number is approx. 10 324. (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 16 / 18

Floating-Point Arithmetic IEEE 754 Are there any numbers exactly represented in our system? (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 17 / 18

Floating-Point Arithmetic IEEE 754 Are there any numbers exactly represented in our system? They must have a finite expansion: x = p ( q = d1 β + d ) 2 β 2 + dt β t (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 17 / 18

Floating-Point Arithmetic IEEE 754 Are there any numbers exactly represented in our system? They must have a finite expansion: x = p ( q = d1 β + d ) 2 β 2 + dt β t Thus, there exists k such that x β k integer (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 17 / 18

Floating-Point Arithmetic IEEE 754 Are there any numbers exactly represented in our system? They must have a finite expansion: x = p ( q = d1 β + d ) 2 β 2 + dt β t Thus, there exists k such that Therefore we must have x β k β k q integer integer (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 17 / 18

Floating-Point Arithmetic IEEE 754 Are there any numbers exactly represented in our system? They must have a finite expansion: x = p ( q = d1 β + d ) 2 β 2 + dt β t Thus, there exists k such that x β k integer Therefore we must have β k q integer but this means that the denominator q only contains prime factors which are also prime factors of β. (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 17 / 18

Floating-Point Arithmetic IEEE 754 Are there any numbers exactly represented in our system? They must have a finite expansion: x = p ( q = d1 β + d ) 2 β 2 + dt β t Thus, there exists k such that x β k integer Therefore we must have β k q integer but this means that the denominator q only contains prime factors which are also prime factors of β. Conclusion: 0.1 10 is NOT exactly representable in binary arithmetic!!!! (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 17 / 18

Properties of operations in floating-point arithmetic In the analysis of algorithms we will assume that the result of any individual arithmetic operation is the rounding of the exact result: This is a requirement of IEEE 754. Floating-point operations are: u v = round(u + v); Commutative (where it makes sense) u v = v u Non associative Non distributive (x y) z x (y z) x (y z) (x y) (x z) (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 18 / 18