Floating Point Numbers

Slides:



Advertisements
Similar presentations
Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
Advertisements

Fixed Point Numbers The binary integer arithmetic you are used to is known by the more general term of Fixed Point arithmetic. Fixed Point means that we.
1 CS61C L9 Fl. Pt. © UC Regents CS61C - Machine Structures Lecture 9 - Floating Point, Part I September 27, 2000 David Patterson
COMP3221: Microprocessors and Embedded Systems Lecture 14: Floating Point Numbers Lecturer: Hui Wu Session 2, 2004.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
CS 61C L15 Floating Point I (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C :
CS61C L11 Floating Point I (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 – Floating.
CS 61C L15 Floating Point I (1) Krause, Spring 2005 © UCB This day in history… TA Danny Krause inst.eecs.berkeley.edu/~cs61c-td inst.eecs.berkeley.edu/~cs61c.
CS 61C L15 Floating Point I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine.
CSE 378 Floating-point1 How to represent real numbers In decimal scientific notation –sign –fraction –base (i.e., 10) to some power Most of the time, usual.
CS 61C L10 Floating Point (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #10: Floating Point
CS61C L15 Floating Point I (1) Jacobs, Spring 2008 © UCB TA Ordinaire Dave Jacobs inst.eecs.berkeley.edu/~cs61c CS61C : Machine.
CS61C L15 Floating Point I (1) Garcia, Fall 2006 © UCB #16 Cal rolls over OSU  Behind the arm of Nate Longshore’s 341 yds passing & 4 TDs, the Bears roll.
IT 251 Computer Organization and Architecture Introduction to Floating Point Numbers Chia-Chi Teng.
Computer Arithmetic Nizamettin AYDIN
Csci 136 Computer Architecture II – Floating-Point Arithmetic
CEN 316 Computer Organization and Design Computer Arithmetic Floating Point Dr. Mansour AL Zuair.
Computing Systems Basic arithmetic for computers.
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
FLOATING POINT ARITHMETIC P&H Slides ECE 411 – Spring 2005.
CS 61C L3.2.1 Floating Point 1 (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Floating Point Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
CHAPTER 3 Floating Point.
CDA 3101 Fall 2013 Introduction to Computer Organization
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Floating Point Representations
Lecture 6. Fixed and Floating Point Numbers
Computer Science 210 Computer Organization
Dr. Clincy Professor of CS
Introduction To Computer Science
Dr. Clincy Professor of CS
Data Representation Binary Numbers Binary Addition
Floating Point Math & Representation
Lecture 9: Floating Point
Floating Point Numbers: x 10-18
CS 232: Computer Architecture II
CS/COE0447 Computer Organization & Assembly Language
April 2006 Saeid Nooshabadi
PRESENTED BY J.SARAVANAN. Introduction: Objective: To provide hardware support for floating point arithmetic. To understand how to represent floating.
William Stallings Computer Organization and Architecture 7th Edition
Floating Point Arithmetics
Data Structures Mohammed Thajeel To the second year students
Topic 3d Representation of Real Numbers
Luddy Harrison CS433G Spring 2007
ECE/CS 552: Floating Point
Number Representations
CS 61C: Great Ideas in Computer Architecture Floating Point Arithmetic
Computer Science 210 Computer Organization
How to represent real numbers
How to represent real numbers
Dr. Clincy Professor of CS
ECEG-3202 Computer Architecture and Organization
Hello to Robb Neuschwander listening from Louisville, KY!
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
Prof. Giancarlo Succi, Ph.D., P.Eng.
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
Lecturer PSOE Dan Garcia
Topic 3d Representation of Real Numbers
CS 286 Computer Architecture & Organization
Numbers with fractions Could be done in pure binary
Computer Organization and Assembly Language
Number Representations
CDA 3101 Spring 2016 Introduction to Computer Organization
Presentation transcript:

Floating Point Numbers Prof. Giancarlo Succi, Ph.D., P.Eng. E-mail: Giancarlo.Succi@unibz.it Prof. G. Succi, Ph.D., P.Eng.

Content Introduction Scientific Notation IEEE 754 Scientific Notation Converting numbers Special numbers Prof. G. Succi, Ph.D., P.Eng.

Numbers since now What can we represent in N bits? Unsigned integers: 0 to 2N – 1 Signed Integers (One’s Complement) -2(N-1) + 1 to 2(N-1) - 1 Signed Integers (Two’s Complement) -2(N-1) to 2(N-1) - 1 … Prof. G. Succi, Ph.D., P.Eng.

Numbers since now What can we represent in 32 bits? Unsigned integers: 0 to 4,294,967,295 Signed Integers (One’s Complement) - 2,147,483,647 to 2,147,483,647 Signed Integers (Two’s Complement) - 2,147,483,648 to 2,147,483,647 Prof. G. Succi, Ph.D., P.Eng.

Regions not covered since now Other numbers Regions covered: Unsigned integers Signed integers -1 1 2 -2,147,483,648 2,147,483,647 4,294,967,295 Regions not covered since now Prof. G. Succi, Ph.D., P.Eng.

Other numbers What about other numbers? Very large numbers? (seconds/century) 3,155,760,00010 (3.1557610 x 109) Very small numbers? (atomic diameter) 0.0000000110 (1.010 x 10-8) Rationals (repeating pattern) 2/3 (0.666666666. . .) Irrationals 21/2 (1.414213562373. . .) Transcendentals e (2.718...),  (3.141...) All represented in scientific notation Prof. G. Succi, Ph.D., P.Eng.

Content Introduction Scientific Notation IEEE 754 Scientific Notation Converting numbers Special numbers Prof. G. Succi, Ph.D., P.Eng.

Scientific Notation exponent mantissa 6.02 x 1023 radix (base) decimal point radix (base) Normalized form: no leadings 0s (exactly one digit to left of decimal point) Alternatives to representing 1/1,000,000,000 Normalized: 1.0 x 10-9 Not normalized: 0.1 x 10-8,10.0 x 10-10 Prof. G. Succi, Ph.D., P.Eng.

Converting base to 2 exponent mantissa 1.0two x 2-1 radix (base) binary point radix (base) Computer arithmetic that supports it called floating point, because it represents numbers where binary point is not fixed, as it is for integers Declare such variables in Java as float Prof. G. Succi, Ph.D., P.Eng.

Binary Scientific Notation in detail 31 S Exponent 30 23 22 Significand 1 bit 8 bits 23 bits Normal format: +1.xxxxxxxxxxtwo*2yyyytwo S represents Sign Exponent represents y’s Significand represents x’s Prof. G. Succi, Ph.D., P.Eng.

Covered Range Regions covered: Largest Exponent: 2128 => 1038 -2.0 x 1038 -2.0 x 10-38 2.0 x 10-38 2.0 x 1038 Underflow Overflow Prof. G. Succi, Ph.D., P.Eng.

Extend covered range 31 30 20 22 1 bit 11 bits 20 bits 32 bits 31 S Exponent 30 20 22 Significand 1 bit 11 bits 20 bits Significand 32 bits Double Precision (vs. Single Precision) C variable declared as double Represent numbers almost as small as 2.0 x 10-308 to almost as large as 2.0 x 10308 But primary advantage is greater accuracy due to larger significand Prof. G. Succi, Ph.D., P.Eng.

Content Introduction Scientific Notation IEEE 754 Scientific Notation Converting numbers Special numbers Prof. G. Succi, Ph.D., P.Eng.

IEEE 754 Floating Point Standard Single Precision, DP similar Sign bit: 1 means negative 0 means positive Significand: To pack more bits, the leading 1 is implicit for normalized numbers 1 + 23 bits single, 1 + 52 bits double always true: Significand < 1 (for normalized numbers) Note: 0 has no leading 1, so reserve exponent value 0 just for number 0 Prof. G. Succi, Ph.D., P.Eng.

IEEE 754: Usability Introduced by Prof. Kahan: to use FP numbers even if no FP hardware is available; e.g., sort records with FP numbers using integer compares It break FP number comparisons into 3 parts: compare signs, then exponents, then significands To improve speed, try to have a single comparison, especially if a number is positive Therefore, … The highest bit is the sign ( negative < positive) Exponent next, so larger exponent  larger # Significand last Prof. G. Succi, Ph.D., P.Eng.

IEEE 754: Signed Exponent Using 2’s comp? 1.0 x 2-1 v. 1.0 x2+1 (1/2 v. 2) 1111 1111 000 0000 0000 0000 0000 0000 1/2 0000 0001 000 0000 0000 0000 0000 0000 2 This notation using integer compare of 1/2 v. 2 makes 1/2 > 2! Instead, pick notation 0000 0001 is smallest negative, and 1111 1111 is the largest positive 1.0 x 2-1 v. 1.0 x2+1 (1/2 v. 2) 1/2 0111 1110 000 0000 0000 0000 0000 0000 1000 0000 2 Prof. G. Succi, Ph.D., P.Eng.

IEEE 754: Summary Called Biased Notation, where bias is number subtract to get real number IEEE 754 uses bias of 127 for single prec. Subtract 127 from Exponent field to get actual value for exponent 1023 is bias for double precision (-1)S x (1 + Significand) x 2(Exponent-127) Double precision identical, except with exponent bias of 1023 Prof. G. Succi, Ph.D., P.Eng.

Content Introduction Scientific Notation IEEE 754 Scientific Notation Converting numbers Special numbers Prof. G. Succi, Ph.D., P.Eng.

Understanding significand: fractions In decimal: 0.34010 => 34010/100010 => 3410/10010 Binary: 0.1102 => 1102/10002 = 610/810 => 112/1002 = 310/410 Advantage: less purely numerical, more thought oriented; this method usually helps people understand the meaning of the significand better Prof. G. Succi, Ph.D., P.Eng.

Understanding significand: positional values Convert from scientific notation In decimal: 1.6732 = (1x100) + (6x10-1) + (7x10-2) + (3x10-3) + (2x10-4) In binary: 1.1001 = (1x20) + (1x2-1) + (0x2-2) + (0x2-3) + (1x2-4) Interpretation of value in each position extends beyond the decimal/binary point Advantage: good for quickly calculating significand value; use this method for translating FP numbers Prof. G. Succi, Ph.D., P.Eng.

Converting Binary FP to Decimal 0110 1000 101 0101 0100 0011 0100 0010 Sign: 0 => positive Exponent: 0110 1000two = 104ten Bias adjustment: 104 - 127 = -23 Significand: 1 + 1x2-1+ 0x2-2 + 1x2-3 + 0x2-4 + 1x2-5 +... =1+2-1+2-3 +2-5 +2-7 +2-9 +2-14 +2-15 +2-17 +2-22 = 1.0 + 0.666115 Represents: 1.666115ten*2-23 ~ 1.986*10-7 (about 2/10,000,000) Prof. G. Succi, Ph.D., P.Eng.

Attention to non-typed data!!! 0011 0100 0101 0101 0100 0011 0100 0010 What does bit pattern mean: 1.986 *10-7? 878,003,010? “4UCB”? ori $s5, $v0, 17218? Data can be anything; operation of instruction that accesses operand determines its type! Side-effect of stored program concept: instructions stored as numbers Power/danger of unrestricted addresses/ pointers: use ASCII as Fl. Pt., instructions as data, integers as instructions, ... (Leads to security holes in programs) Prof. G. Succi, Ph.D., P.Eng.

Converting Decimal to FP Simple Case: If denominator is an exponent of 2 (2, 4, 8, 16, etc.), then it’s easy. Show MIPS representation of -0.75 -0.75 = -3/4 -11two/100two = -0.11two Normalized to -1.1two x 2-1 (-1)S x (1 + Significand) x 2(Exponent-127) (-1)1 x (1 + .100 0000 ... 0000) x 2(126-127) 1 0111 1110 100 0000 0000 0000 0000 0000 Prof. G. Succi, Ph.D., P.Eng.

Converting Decimal to FP If denominator is not an exponent of 2… Then we cannot represent the number precisely, but that’s why we have so many bits in significand: for precision Once we have the significand, normalizing a number to get the exponent is easy So how do we get the significand? Prof. G. Succi, Ph.D., P.Eng.

Converting Decimal to FP: Rationale Fact: All rational numbers have a repeating pattern when written out in decimal. Fact: This still applies in binary. To finish conversion: Write out binary number with repeating pattern. Cut it off after correct number of bits (different for single v. double precision). Derive Sign, Exponent and Significand fields. Prof. G. Succi, Ph.D., P.Eng.

Conversion: Example How to represent 1/3 in MIPS? 1/3 = 0.33333…10 = 0.25 + 0.0625 + 0.015625 + 0.00390625 + 0.0009765625 + … = 1/4 + 1/16 + 1/64 + 1/256 + 1/1024 + … = 2-2 + 2-4 + 2-6 + 2-8 + 2-10 + … = 0.0101010101… 2 * 20 = 1.0101010101… 2 * 2-2 Prof. G. Succi, Ph.D., P.Eng.

Conversion: Example Sign: 0 Exponent = -2 + 127 = 12510=011111012 Significand = 0101010101… 0111 1101 0101 0101 0101 0101 0101 010 Prof. G. Succi, Ph.D., P.Eng.

Content Introduction Scientific Notation IEEE 754 Scientific Notation Converting numbers Special numbers Prof. G. Succi, Ph.D., P.Eng.

Representation for +/- Infinity In FP, divide by zero should produce +/- infinity, not overflow. Why? OK to do further computations with infinity e.g., X/0 > Y may be a valid comparison IEEE 754 represents +/- infinity Highest positive exponent reserved for infinity Significand: all zeroes Prof. G. Succi, Ph.D., P.Eng.

Representation for 0 Represent 0? Why two zeros? exponent all zeros significand all zeros too What about sign? +0: 0 00000000 00000000000000000000000 -0: 1 00000000 00000000000000000000000 Why two zeros? Helps in some comparisons Prof. G. Succi, Ph.D., P.Eng.

Special numbers: summary What have we defined so far? (Single Precision) Exponent Significand Object 0 0 0 0 nonzero ??? 1-254 anything +/- fl. pt. # 255 0 +/- infinity 255 nonzero ??? Prof. G. Succi, Ph.D., P.Eng.

Proposed Example What value is represented by: 1 1000 0001 111 0000 0000 0000 0000 0000 Prof. G. Succi, Ph.D., P.Eng.

Proposed Example: solution What value is represented by: 1 1000 0001 111 0000 0000 0000 0000 0000 S Exponent Significand (-1)S x (1 + Significand) x 2(Exponent-127) (-1)1 x (1 + .111) x 2(129-127) -1 x (1.111) x 2(2) = -111.12 = -7. 5 Prof. G. Succi, Ph.D., P.Eng.

Things to Remember Floating Point numbers approximate the values that we want to use. IEEE 754 Floating Point Standard is the most widely accepted attempt to standardize interpretation of such numbers Every desktop computer sold since ~1997 follows these conventions Type is not associated with data, bits have no meaning unless given in context Prof. G. Succi, Ph.D., P.Eng.