Floating Point Arithmetic

Similar documents
Chapter Three. Arithmetic

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Divide: Paper & Pencil

Floating-point representations

Floating-point representations

Chapter 3: Arithmetic for Computers

3.5 Floating Point: Overview

IEEE Standard for Floating-Point Arithmetic: 754

Floating Point Numbers

Module 2: Computer Arithmetic

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

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

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

Chapter 3 Arithmetic for Computers (Part 2)

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

CO212 Lecture 10: Arithmetic & Logical Unit

Computer Architecture Set Four. Arithmetic

ECE232: Hardware Organization and Design

Signed Multiplication Multiply the positives Negate result if signs of operand are different

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

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Numeric Encodings Prof. James L. Frankel Harvard University

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

COMP2611: Computer Organization. Data Representation

Scientific Computing. Error Analysis

CS 101: Computer Programming and Utilization

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point Numbers. Lecture 9 CAP

Computer Arithmetic Floating Point

Number Systems. Both numbers are positive

Review: MULTIPLY HARDWARE Version 1. ECE4680 Computer Organization & Architecture. Divide, Floating Point, Pentium Bug

15213 Recitation 2: Floating Point

Data Representation Floating Point

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Number Systems and Computer Arithmetic

Inf2C - Computer Systems Lecture 2 Data Representation

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

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

Floating Point COE 308. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

IEEE-754 floating-point

Floating Point Numbers

Floating Point Numbers

Divide: Paper & Pencil CS152. Computer Architecture and Engineering Lecture 7. Divide, Floating Point, Pentium Bug. DIVIDE HARDWARE Version 1

Data Representation Floating Point

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

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

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

Foundations of Computer Systems

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

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

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

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

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

Chapter 4. Operations on Data

CS101 Lecture 04: Binary Arithmetic

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

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

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

Floating Point January 24, 2008

CMPSCI 145 MIDTERM #2 SPRING 2017 April 7, 2017 Professor William T. Verts NAME PROBLEM SCORE POINTS GRAND TOTAL 100

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive.

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

Up next. Midterm. Today s lecture. To follow

Characters, Strings, and Floats

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

CS429: Computer Organization and Architecture

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

System Programming CISC 360. Floating Point September 16, 2008

CS 61C: Great Ideas in Computer Architecture Floating Point Arithmetic

Number Representations

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Organisasi Sistem Komputer

MIPS Integer ALU Requirements

CO Computer Architecture and Programming Languages CAPL. Lecture 15

IEEE 754 Floating-Point Format

ecture 25 Floating Point Friedland and Weaver Computer Science 61C Spring 2017 March 17th, 2017

Giving credit where credit is due

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

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Floating Point Arithmetic

CS101 Introduction to computing Floating Point Numbers

±M R ±E, S M CHARACTERISTIC MANTISSA 1 k j

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

Giving credit where credit is due

Signed umbers. Sign/Magnitude otation

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

Classes of Real Numbers 1/2. The Real Line

UNIT-III COMPUTER ARTHIMETIC

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic

Representing and Manipulating Floating Points

Today: Floating Point. Floating Point. Fractional Binary Numbers. Fractional binary numbers. bi bi 1 b2 b1 b0 b 1 b 2 b 3 b j

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

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

Floating-Point Arithmetic

Transcription:

Floating Point Arithmetic CS 365 Floating-Point What can be represented in N bits? Unsigned 0 to 2 N 2s Complement -2 N-1 to 2 N-1-1 But, what about? very large numbers? 9,349,398,989,787,762,244,859,087,678 very small number? 0.0000000000000000000000045691 rationals 2/3 irrationals transcendentals 2 e, π 1

Floating Point We need a way to represent numbers with fractions, e.g., 3.1416 very small numbers, e.g.,.000000001 very large numbers, e.g., 3.15576 10 9 Representation: sign, exponent, significand: ( 1) sign significand 2 exponent more bits for significand gives more accuracy more bits for exponent increases range IEEE 754 floating point standard: single precision: 8 bit exponent, 23 bit significand double precision: 11 bit exponent, 52 bit significand Recall Scientific Notation decimal point exponent Sign, magnitude 23-24 6.02 x 10 1.673 x 10 Mantissa radix (base) Sign, magnitude IEEE F.P. ± 1.M x 2 e - 127 Issues: Arithmetic (+, -, *, / ) Representation, Normal form Range and Precision Rounding Exceptions (e.g., divide by zero, overflow, underflow) Errors 2

IEEE 754 floating-point standard Leading 1 bit of significand is implicit Exponent is biased to make sorting easier all 0s is smallest exponent all 1s is largest bias of 127 for single precision and 1023 for double precision summary: ( 1) sign (1+significand) 2exponent bias Example: decimal: -.75 = -3/4 = -3/2 2 binary: -.11 = -1.1 x 2-1 floating point: exponent = 126 = 01111110 IEEE single precision: 10111111010000000000000000000000 IEEE 754 Standard Representation of floating point numbers in IEEE 754 standard: 1 8 23 single precision sign S E M actual exponent is e = E - 127 exponent: bias 127 binary integer 0 < E < 255 S E-127 N = (-1) 2 (1.M) 0 = 0 00000000 0... 0-1.5 = 1 01111111 10... 0 mantissa: sign + magnitude, normalized binary significand w/ hidden integer bit: 1.M Magnitude of numbers that can be represented is in the range: 2-126 (1.0) to 2 127 (2-2 -23 ) which is approximately: 1.8 x 10-38 to 3.40 x 10 38 3

Floating Point Complexities Operations are somewhat more complicated In addition to overflow we can have underflow Accuracy can be a big problem IEEE 754 keeps two extra bits, guard and round four rounding modes positive divided by zero yields infinity zero divide by zero yields not a number other complexities Implementing the standard can be tricky Not using the standard can be even worse see text for description of 80x86 and Pentium bug! Floating Point Addition Example Example: Add 9.999 10 1 and 1.610 10-1 assuming 4 decimal digits 1. Allign decimal point of number with smaller exponent 1.610 10-1 = 0.161 10 0 = 0.0161 10 1 Shift smaller number to right 2. Add significands 9.999 0.016 10.015 SUM = 10.015 10 1 NOTE: One digit of precision lost during shifting. Also sum is not normalized 3. Shift sum to put it in normalized form 1.0015 10 2 4. Since significand only has 4 digits, we need to round the sum SUM = 1.002 10 2 NOTE: normalization maybe needed again after rounding, e.g, rounding 9.9999 you get 10.000 4

Start 1. Compare the exponents of the two numbers. Shift the smaller number to the right until its exponent would match the larger exponent 2. Add the significands 3. Normalize the sum, either shifting right and incrementing the exponent or shifting left and decrementing the exponent Overflow or underflow? Yes No Exception 4. Round the significand to the appropriate number of bits No Still normalized? Yes Done Sign Exponent Significand Sign Exponent Significand Small ALU Compare exponents Exponent difference 0 1 0 1 0 1 Control Shift right Shift smaller number right Big ALU Add 0 1 Increment or decrement 0 1 Shift left or right Normalize Rounding hardware Round Sign Exponent Significand 5

Accurate Arithmetic Guard & Round bits IEEE 754 standard specifies the use of 2 extra bits on the right during intermediate calculations Guard bit and Round bit Example: Add 2.56 10 0 and 2.34 10 2 assuming 3 significant digits and without guard and round bits 2.56 10 0 = 0.0256 10 2 2.34 0.02 2.36 10 2 With guard and round bits 2.34 0.0256 2.3656 10 2 ROUND 2.37 10 0 Chapter Four Summary Computer arithmetic is constrained by limited precision Bit patterns have no inherent meaning but standards do exist two s complement IEEE 754 floating point Computer instructions determine meaning of the bit patterns Performance and accuracy are important so there are many complexities in real machines (i.e., algorithms and implementation). Next class: we are ready to move on (and implement the processor) 6