COMP3221 lec19-fp-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 19 : Floating Point Number Representation – I

Slides:



Advertisements
Similar presentations
1 Floating Point Representation and Arithmetic (see Patterson Chapter 4)
Advertisements

A Simple ALU Binary Logic.
Prof. Dr. Nizamettin AYDIN edu. tr
Fixed-point and floating-point numbers CS370 Fall 2003.
UNIVERSITY OF MASSACHUSETTS Dept
COMP3221 lec20-fp-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 20 : Floating Point Number Representation – II
COMP3211 lec21-fp-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 21 : Floating Point Number Representation – III
Datorteknik IntegerAddSub bild 1 Integer arithmetic Depends what you mean by "integer" Assume at 3-bit string. –Then we define zero = 000 one = 001 Use.
14-1 Bard, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Embedded Systems Lecture 14: Gaming Engines, Coding Style, Floating Point.
Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
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.
CENG536 Computer Engineering department Çankaya University.
1 IKI10230 Pengantar Organisasi Komputer Bab 6: Aritmatika 7 & 14 Mei 2003 Bobby Nazief Qonita Shahab bahan kuliah:
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Floating Point Numbers
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.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
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.
1 Lecture 4: Arithmetic for Computers (Part 5) CS 447 Jason Bakos.
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.
1 Module 2: Floating-Point Representation. 2 Floating Point Numbers ■ Significant x base exponent ■ Example:
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.
ECEN 248 Integer Multiplication, Number Format Adopted from Copyright 2002 David H. Albonesi and the University of Rochester.
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.
Computer Science 210 Computer Organization Floating Point Representation.
IT 251 Computer Organization and Architecture Introduction to Floating Point Numbers Chia-Chi Teng.
Ch. 2 Floating Point Numbers
Computer Arithmetic Nizamettin AYDIN
Number Systems II Prepared by Dr P Marais (Modified by D Burford)
Csci 136 Computer Architecture II – Floating-Point Arithmetic
CEN 316 Computer Organization and Design Computer Arithmetic Floating Point Dr. Mansour AL Zuair.
IT253: Computer Organization
Floating Point Numbers Topics –IEEE Floating Point Standard –Rounding –Floating Point Operations –Mathematical properties.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Data Representation in Computer Systems
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CSC 221 Computer Organization and Assembly Language
CSC 4250 Computer Architectures September 5, 2006 Appendix H. Computer Arithmetic.
Integer and Fixed Point P & H: Chapter 3
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.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
CS 232: Computer Architecture II
April 2006 Saeid Nooshabadi
PRESENTED BY J.SARAVANAN. Introduction: Objective: To provide hardware support for floating point arithmetic. To understand how to represent floating.
Chapter 6 Floating Point
Arithmetic for Computers
Topic 3d Representation of Real Numbers
Luddy Harrison CS433G Spring 2007
Number Representations
CS201 - Lecture 5 Floating Point
CS 61C: Great Ideas in Computer Architecture Floating Point Arithmetic
Hello to Robb Neuschwander listening from Louisville, KY!
Floating Point Numbers
Lecturer PSOE Dan Garcia
Topic 3d Representation of Real Numbers
Number Representations
CDA 3101 Spring 2016 Introduction to Computer Organization
Presentation transcript:

COMP3221 lec19-fp-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 19 : Floating Point Number Representation – I September, 2003 Saeid Nooshabadi

COMP3221 lec19-fp-I.2 Saeid Nooshabadi Overview °Floating Point Numbers °Motivation: Decimal Scientific Notation Binary Scientific Notation °Floating Point Representation inside computer (binary) Greater range, precision °IEEE-754 Standard

COMP3221 lec19-fp-I.3 Saeid Nooshabadi Review of Numbers °Computers are made to deal with numbers °What can we represent in N bits? Unsigned integers: 0to2 N - 1 Signed Integers (Two’s Complement) -2 (N-1) to 2 (N-1) - 1

COMP3221 lec19-fp-I.4 Saeid Nooshabadi Other Numbers °What about other numbers? Very large numbers? (seconds/century) 3,155,760, ( x 10 9 ) Very small numbers? (atomic diameter) ( x ) Rationals (repeating pattern) 2/3 ( ) Irrationals 2 1/2 ( ) Transcendentals e ( ),  ( ) °All represented in scientific notation

COMP3221 lec19-fp-I.5 Saeid Nooshabadi Scientific Notation Review 6.02 x radix (base) decimal pointmantissa/significand 6.02 Exponent 23 °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 Not normalized: 0.1 x 10 -8,10.0 x How to represent 0 in Normalized form? fraction 02 6 Integer

COMP3221 lec19-fp-I.6 Saeid Nooshabadi Interesting Properties °Finite precision i.e. the number of bits in which to represent the significand and exponent is limited. Thus not all non-integer values can be represented exactly. Example: represent 1.32 as d 3 d 1 d 2.f 1 x 10 (no digit after the decimal point)

COMP3221 lec19-fp-I.7 Saeid Nooshabadi Floating Point Number Range vs Precision (#1/4) °For simplicity, assume integer Representation for Significand. °Represent N by d 1 d 2 d 3, where d3d3 N = d 1 d 2 x 10 d2d3d2d3 N = d 1 x 10 d 3 N = d 1 d 2 x 100

COMP3221 lec19-fp-I.8 Saeid Nooshabadi Floating Point Number Range vs Precision (#2/4) °Which representation can represent the largest value? d3d3 N = d 1 d 2 x 10 d2d3d2d3 N = d 1 x 10 d 3 N = d 1 d 2 x N = 99 x 10 = 9.9 x N = 9 x N = 99 x 100 = 9.9 x 10

COMP3221 lec19-fp-I.9 Saeid Nooshabadi Floating Point Number Range vs Precision (#3/4) °In which representation can the most different values be represented? d3d3 N = d 1 d 2 x 10 d2d3d2d3 N = d 1 x 10 d 3 N = d 1 d 2 x 100 °All can represent the same number of different values. °Two of the systems can represent an equal number of values, more than the third. °#3 can represent more values than the other two. °#2 can represent more values than the other two. °#1 can represent more values than the other two

COMP3221 lec19-fp-I.10 Saeid Nooshabadi Floating Point Number Range vs Precision (#4/4) °In which representation can the most different values be represented? d3d3 N = d 1 d 2 x x = 991 d2d3d2d3 N = d 1 x 10 9 x = 901 d 3 N = d 1 d 2 x x = 991 °All can represent the same number of different values. °Two of the systems can represent an equal number of values, more than the third. °#3 can represent more values than the other two. °#2 can represent more values than the other two. °#1 can represent more values than the other two

COMP3221 lec19-fp-I.11 Saeid Nooshabadi Scientific Notation for Binary Numbers 1.0 two x 2 -1 radix (base) “binary point”significand exponent °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 variable in C as float

COMP3221 lec19-fp-I.12 Saeid Nooshabadi Properties of a good FP Number rep. °Represents many useful numbers most of the 2 N possible are useful How many LARGE? How many small? °Easy to do arithmetic ( +, -, *, / ) °Easy to do comparison ( ==, ) °Nice mathematical properties A != B => A - B != 0

COMP3221 lec19-fp-I.13 Saeid Nooshabadi Floating Point Representation (#1/2) °Normal format: +1.xxxxxxxxxx two *2 yyyy two °Multiple of Word Size (32 bits) 0 31 SExponent Significand 1 bit8 bits23 bits °S represents Sign °Exponent represents y’s °Significand represents x’s °Leading 1 in Significand is implied °Represent numbers as small as 2.0 x to as large as 2.0 x 10 38

COMP3221 lec19-fp-I.14 Saeid Nooshabadi Floating Point Representation (#2/2) °What if result too large? (> 2.0x10 38 ) Overflow! Overflow => Exponent larger than represented in 8-bit Exponent field °What if result too small? (<0, < 2.0x ) Underflow! Underflow => Negative exponent larger than represented in 8-bit Exponent field °How to reduce chances of overflow or underflow?

COMP3221 lec19-fp-I.15 Saeid Nooshabadi Double Precision Fl. Pt. Representation °Next Multiple of Word Size (64 bits) °Double Precision (vs. Single Precision) C variable declared as double Represent numbers almost as small as 2.0 x to almost as large as 2.0 x But primary advantage is greater accuracy due to larger significand 0 31 SExponent Significand 1 bit11 bits20 bits Significand (cont’d) 32 bits

COMP3221 lec19-fp-I.16 Saeid Nooshabadi Fl. Pt. Hardware °Microprocessors do floating point computation using a special coprocessor. works under the processor supervision Has its own set of registers °Most low end processors do not have Ft. Pt. Coprocessors Ft. Pt. Computation by software emulation ARM processor on DSLMU board does not have Ft. Pt. Coprocessor Some high end ARM processors do

COMP3221 lec19-fp-I.17 Saeid Nooshabadi IEEE 754 Floating Point Standard (#1/6) °Single Precision, (DP similar) °Sign bit:1 means negative 0 means positive °Significand: To pack more bits, leading 1 implicit for normalized numbers. (Hidden Bit) bits single, bits double always true: 0 < Significand < 1 (for normalized numbers) °What about Zero? Next Lecture

COMP3221 lec19-fp-I.18 Saeid Nooshabadi IEEE 754 Floating Point Standard (#2/6) °Kahan* wanted FP numbers to be used even if no FP hardware; e.g., sort records with FP numbers using integer compares °Wanted Compare to be faster, by means of a single compare operation, used for integer numbers, especially if positive FP numbers °How to order 3 parts (Sign, Significand and Exponent) to simplify compare? The Author of IEEE 754 FP Standard ieee754status/754story.html

COMP3221 lec19-fp-I.19 Saeid Nooshabadi IEEE 754 Floating Point Standard (#3/6) °“ Natural”: Sign, Fraction, Exponent? Problem: If want to sort using integer compare operations, won’t work: 1.0 x 2 20 vs. 1.1 x 2 10 ; latter looks bigger! °Exponent, Sign, Fraction? Need to get sign first, since negative < positive °How to order 3 Fields in a Word? +1.xxxxxxxxxx two *2 yyyy two °Therefore order is Sign Exponent Fraction 1.0 x > 1.1 x SExponent Significand

COMP3221 lec19-fp-I.20 Saeid Nooshabadi IEEE 754 Floating Point Standard (#4/6) °Want compare Fl.Pt. numbers as if integers, to help in sort Sign first part of number Exponent next, so big exponent => bigger No. °Negative Exponent? 2’s comp? 1.0 x 2 -1 vs 1.0 x2 +1 (1/2 vs 2) This notation using integer compare of 1/2 vs 2 makes 1/2 > 2! /2 2

COMP3221 lec19-fp-I.21 Saeid Nooshabadi °Instead, pick notation: is most negative, is most positive Called Biased Notation; bias subtracted to get number 127 in Single Prec. (1023 D.P.) IEEE 754 Floating Point Standard (#5/6) °2’s comp? 1.0 x 2 -1 vs 1.0 x2 +1 (1/2 vs 2) This notation using integer compare of 1/2 vs 2 makes 2 look greater than 1/ /2 2

COMP3221 lec19-fp-I.22 Saeid Nooshabadi IEEE 754 Floating Point Standard (#6/6) °Summary (single precision): 0 31 SExponent Significand 1 bit8 bits23 bits °(-1) S x (1 + Significand) x 2 (Exponent-127) °Double precision identical, except with exponent bias of 1023

COMP3221 lec19-fp-I.23 Saeid Nooshabadi Floating Point Number Distribution Using mantissa of and positive exponents x x x x 2 3 and Sign bit x x x x and negative exponents x x x 2 -3 in each of the intervals of exponentially increasing size can represent 2 S (s=3 here) numbers of uniform difference x x x x x x x 2 2 But how do we represent 0? Which numbers can be represented? Next Lecture!

COMP3221 lec19-fp-I.24 Saeid Nooshabadi “And in Conclusion..” °Number of digits allocated to significand and exponent, and choice of base, can affect both the number of different representable values and the range of values. °Finite precision means we have to cope with roundoff error (arithmetic with inexact values) and truncation error (large values overwhelming small ones). °IEEE 754 Standard allows Single Precision (1 word) and Double Precision (2-word) representation of FP. Nos.