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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Fabián E. Bustamante, Spring 2007 Floating point Today IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Datorteknik FloatingPoint bild 1 Floating point Number system corresponding to the decimal notation 1,837 * 10 significand exponent a great number of corresponding.
Floating Point Numbers
University of Washington Today Topics: Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
1  2004 Morgan Kaufmann Publishers Chapter Three.
Floating Point Numbers
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Numbers and number systems
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Number Systems II Prepared by Dr P Marais (Modified by D Burford)
CEN 316 Computer Organization and Design Computer Arithmetic Floating Point Dr. Mansour AL Zuair.
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Computing Systems Basic arithmetic for computers.
ECE232: Hardware Organization and Design
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
S. Rawat I.I.T. Kanpur. Floating-point representation IEEE numbers are stored using a kind of scientific notation. ± mantissa * 2 exponent We can represent.
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
Lecture 9: Floating Point
CSC 221 Computer Organization and Assembly Language
Floating Point Arithmetic
Integer and Fixed Point P & H: Chapter 3
Computer Arithmetic Floating Point. We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large.
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.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Floating Point Numbers Representation, Operations, and Accuracy CS223 Digital Design.
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
Numbers in Computers.
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.
Floating Point Representations
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
2.4. Floating Point Numbers
Integer Division.
Lecture 9: Floating Point
Topics IEEE Floating Point Standard Rounding Floating Point Operations
Floating Point Number system corresponding to the decimal notation
CS 232: Computer Architecture II
CS/COE0447 Computer Organization & Assembly Language
Topic 3d Representation of Real Numbers
ECE/CS 552: Floating Point
CSCE 350 Computer Architecture
Number Representations
EEL 3705 / 3705L Digital Logic Design
How to represent real numbers
How to represent real numbers
Computer Arithmetic Multiplication, Floating Point
ECEG-3202 Computer Architecture and Organization
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
Floating Point Numbers
Topic 3d Representation of Real Numbers
Number Representations
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

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 representation 1 digit at left of decimal point –Example: x 10 6 A number is normalized if the leading digit is not 0 –Example: x 10 5

CSE 378 Floating-point2 Real numbers representation inside computer Use a representation akin to scientific notation sign x mantissa x base exponent Many variations in choice of representation for –mantissa (could be 2’s complement, sign and magnitude etc.) –base (could be 2, 8, 16 etc.) –exponent (cf. mantissa) Arithmetic support for real numbers is called floating-point arithmetic

CSE 378 Floating-point3 Floating-point representation: IEEE Standard Basic choices –A single precision number must fit into 1 word (4 bytes, 32 bits) –A double precision number must fit into 2 words –The base for the exponent is 2 –There should be approximately as many positive and negative exponents Additional criteria –The mantissa will be represented in sign and magnitude form –Numbers will be normalized

CSE 378 Floating-point4 Example: MIPS representation of IEEE Standard A number is represented as : (-1) S. F.2 E In single precision the representation is: sexponentmantissa bits23 bits

CSE 378 Floating-point5 MIPS representation (ct’ed) Bit 31 sign bit for mantissa (0 pos, 1 neg) Exponent 8 bits (“biased” exponent, see next slide) mantissa 23 bits : always a fraction with an implied binary point at left of bit 22 Number is normalized (see implication next slides) 0 is represented by all zero’s. Note that having the most significant bit as sign bit makes it easier to test for positive and negative.

CSE 378 Floating-point6 Biased exponent The “middle” exp. ( ) will represent exponent 0 All exps starting with a “1” will be positive exponents. –Example: is exponent 2 ( ) All exps starting with a “0” will be negative exponents –Example is exponent -1 ( ) The largest positive exponent will be , yielding a maximum number of absolute value about The smallest negative exponent is yielding a minimum number of absolute value about Note the advantage of this notation for sorting

CSE 378 Floating-point7 Normalization Since numbers must be normalized, there is an implicit “one” at the left of the binary point. No need to put it in (improves precision by 1 bit) But need to reinstate it when performing operations. In summary, in MIPS a floating-point number has the value: (-1) S. (1 + mantissa). 2 (exponent - 127)

CSE 378 Floating-point8 Examples of representation is: – (1+0) i.e., …000 2 is : +(1+0). 2 1 i.e., … is: +(1+0.25). 2 1 i.e., … is in binary … so 0.33 is: +( …) i.e., …

CSE 378 Floating-point9 Double precision Takes 2 words (64 bits) Exponent 11 bits (instead of 8) Mantissa 52 bits (instead of 23) Still biased exponent and normalized numbers Still 0 is represented by all zeros We can still have overflow (the exponent cannot handle super big numbers) and underflow (the exponent cannot handle super small numbers)

CSE 378 Floating-point10 Floating-Point Addition Quite “complex” (more complex than multiplication) Need to know which of the addends is larger (compare exponents) Need to shift “smaller” mantissa Need to know if mantissas have to be added or subtracted (since sign and magnitude representation) Need to normalize the result Correct round-off procedures is not simple (not covered in detail here)

CSE 378 Floating-point11 One of the 4 round-off modes Round to nearest even –Example 1: in base 10. Assume 2 digit accuracy. 3.1 * * = * 10 0 clearly should be rounded to 3.1 * 10 0 –Example 2: 3.1 * * = 3.15 * 10 0 By convention, round-off to nearest “even” number 3.2 * 10 0 Other round-off modes: towards 0, +∞, -∞

CSE 378 Floating-point12 F-P add (details for round-off omitted) 1. Compare exponents. If e1 < e2, swap the 2 operands such that d = e1 - e2 >= 0. Tentatively set exponent of result to e1 and sign of result to s1 2. Insert 1’s at left of mantissas. If the signs of operands differ, replace 2nd mantissa by its 2’s complement. 3. Shift 2nd mantissa d bits to the right (this is an arithmetic shift, i.e., insert either 1’s or 0’s depending on the sign of the second operand) 4. Add the (shifted) mantissas. (There is one case where the result could be the opposite of s1 and you have to take the 2’s complement; this can happen only when d = 0, the signs of the operands are different, and abs(m1) < abs(m2).) 5. Normalize (if there was a carry-out in step 4, shift right once; else shift left until the first “1” appears on msb) 6. Modify exponent to reflect the number of bits shifted in previous step

CSE 378 Floating-point13 Using pipelining Stage 1 –Exponent compare Stage 2 –Shift and Add Stage 3 –Round-off, normalize and fix exponent Most of the time, done in 2 stages.

CSE 378 Floating-point14 Floating-point multiplication Conceptually easier 1. Add exponents (careful, subtract one “bias”) 2. Multiply mantissas (don’t have to worry about signs) 3. Normalize and round-off and get the correct sign

CSE 378 Floating-point15 Pipelining Use tree of “carry-save adders” (cf. CSE 370) Can cut-it off in several stages depending on hardware available Have a “regular” adder in the last stage.

CSE 378 Floating-point16 Special Values Allow computation to continue in face of exceptional conditions –For example: divide by 0, overflow, underflow Special value: NaN (Not a Number; e.g., sqrt(-1)) –Operations such as 1 + NaN yield NaN Special values: +∞ and -∞ (e.g, 1/0 is +∞) Can also use “denormal” numbers for underflow and overflow allowing a wider range of values.