IEEE 754 Floating-Point Format

Similar documents
IEEE 754 Floating-Point Format

Programming & Data Structure: CS Section - 1/A DO NOT POWER ON THE MACHINE

DS: CS Computer Sc & Engg: IIT Kharagpur 1. roblem Set III. Goutam Biswas

Floating Point Arithmetic

COMP2611: Computer Organization. Data Representation

Numeric Encodings Prof. James L. Frankel Harvard University

World Inside a Computer is Binary

15213 Recitation 2: Floating Point

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

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

CS101 Introduction to computing Floating Point Numbers

INTEGER REPRESENTATIONS

IEEE Standard for Floating-Point Arithmetic: 754

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

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

IEEE-754 floating-point

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

Data Representation in Computer Memory

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

Chapter Three. Arithmetic

MACHINE LEVEL REPRESENTATION OF DATA

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

Basic Assignment and Arithmetic Operators

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

Data Representation Floating Point

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

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

Name Roll No. Section

ECE232: Hardware Organization and Design

CS101 Lecture 04: Binary Arithmetic

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

Floating Point Numbers

Floating Point Numbers

Number Systems. Both numbers are positive

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

Floating Point Arithmetic


Module 2: Computer Arithmetic

COMP2121: Microprocessors and Interfacing. Number Systems

Data Representation Floating Point

Chapter 3: Arithmetic for Computers

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

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

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

Lecture 25: Other Number Systems

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Representing and Manipulating Floating Points. Jo, Heeseung

PDS: CS Computer Sc & Engg: IIT Kharagpur 1. for Statement

Representing and Manipulating Floating Points

Characters, Strings, and Floats

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Programming with Indexed Variables

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

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

3.5 Floating Point: Overview

Floating Point. EE 109 Unit 20. Floating Point Representation. Fixed Point

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

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

Floating Point Representation in Computers

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

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

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.

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Introduction to Scientific Computing Lecture 1

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

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point Numbers. Lecture 9 CAP

CS 101: Computer Programming and Utilization

Floating Point Numbers

Signed umbers. Sign/Magnitude otation

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

ECE331: Hardware Organization and Design

Floa=ng- Point Numbers

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

What Every Programmer Should Know About Floating-Point Arithmetic

Representing and Manipulating Floating Points

UNIT 7A Data Representation: Numbers and Text. Digital Data

Description Hex M E V smallest value > largest denormalized negative infinity number with hex representation 3BB0 ---

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

IEEE Floating Point Numbers Overview

Number of decimal places of precision has reduced! We supplied a value correct to 12 decimal places

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

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

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

User Defined Data: Product Constructor

Representing and Manipulating Floating Points

Inf2C - Computer Systems Lecture 2 Data Representation

Classes of Real Numbers 1/2. The Real Line

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

Today CISC124. Building Modular Code. Designing Methods. Designing Methods, Cont. Designing Methods, Cont. Assignment 1 due this Friday, 7pm.

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

unused unused unused unused unused unused

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

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

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

Integer Representation Floating point Representation Other data types

Transcription:

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 IEEE 754 Floating-Point Format

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Floating-Point Decimal Number 123456. 10 1 = 12345.6 10 0 = 1234.56 10 1 = 123.456 10 2 = 12.3456 10 3 = 1.23456 10 4 (normalised) 0.12345 10 5 0.01234 10 6

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 3 Note There are different representations for the same number and there is no fixed position for the decimal point. Given a fixed number of digits, there may be a loss of precession. Three pieces of information represents a number: sign of the number, the significant value and the signed exponent of 10.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 4 Note Given a fixed number of digits, the floating-point representation covers a wider range of values compared to a fixed-point representation.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 5 Example The range of a fixed-point decimal system with six digits, of which two are after the decimal point, is 0.00 to 9999.99. The range of a floating-point representation of the form m.mmm 10 ee is 0.0, 0.001 10 0 to 9.999 10 99. Note that the radix-10 is implicit.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 6 In a C Program Data of type float and double are represented as binary floating-point numbers. These are approximations of real numbers a like an int, an approximation of integers. a In general a real number may have infinite information content. It cannot be stored in the computer memory and cannot be processed by the CPU.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 7 IEEE 754 Standard Most of the binary floating-point representations follow the IEEE-754 standard. The data type float uses IEEE 32-bit single precision format and the data type double uses IEEE 64-bit double precision format. A floating-point constant is treated as a double precision number by GCC.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 9 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 s exponent significand/mantissa 1 bit 8 bits 23 bits Single Precession (32 bit) 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 s exponent significand/mantissa 1 bit 11 bits 20 bits significand (continued) 32 bits Double Precession (64 bit)

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 24 Single Precession Normalized Number Let the sign bit (31) be s, the exponent (30-23) be e and the mantissa (significand or fraction) (22-0) be m. The valid range of the exponents is 1 to 254 (if e is treated as an unsigned number). The actual exponent is biased by 127 to get e i.e. the actual value of the exponent is e 127. This gives the range: 2 1 127 = 2 126 to 2 254 127 = 2 127.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 25 Single Precession Normalized Number The normalized significand is 1.m (binary dot). The binary point is before bit-22 and the 1 (one) is not present explicitly. The sign bit s = 1 for a ve number is zero (0) for a +ve number. The value of a normalized number is ( 1) s 1.m 2 e 127

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 26 An Example Consider the following 32-bit pattern 1 1011 0110 011 0000 0000 0000 0000 0000 The value is ( 1) 1 2 10110110 01111111 1.011 = 1.375 2 55 = 49539595901075456.0 = 4.9539595901075456 10 16

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 27 An Example Consider the decimal number: +105.625. The equivalent binary representation is +1101001.101 = +1.101001101 2 6 = +1.101001101 2 133 127 = +1.101001101 2 10000101 01111111 In IEEE 754 format: 0 1000 0101 101 0011 0100 0000 0000 0000

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 28 An Example Consider the decimal number: +2.7. The equivalent binary representation is +10.10 1100 1100 1100 = +1.010 1100 1100 2 1 = +1.010 1100 1100 2 128 127 = +1.010 1100 2 10000000 01111111 In IEEE 754 format (approximate): 0 1000 0000 010 1100 1100 1100 1100 1101

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 29 Range of Significand The range of significand for a 32-bit number is 1.0 to (2.0 2 23 ).

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 33 Note The smallest magnitude of a normalized number in single precession is ± 0000 0001 000 0000 0000 0000 0000 0000, whose value is 1.0 2 126. The largest magnitude of a normalized number in single precession is ± 1111 1110 111 1111 1111 1111 1111 1111, whose value is 1.99999988 2 127 3.403 10 38.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 34 Note The smallest magnitude of a subnormal number in single precession is ± 0000 0000 000 0000 0000 0000 0000 0001, whose value is 2 126+( 23) = 2 149. The largest magnitude of a subnormal number in single precession is ± 0000 0000 111 1111 1111 1111 1111 1111, whose value is 0.99999988 2 126.

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 37 Note Infinity: : 1111 1111 000 0000 0000 0000 0000 0000 is greater than (as an unsigned integer) the largest normal number: 1111 1110 111 1111 1111 1111 1111 1111

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 40 #include <stdio.h> int main() // twozeros.c { double a = 0.0, b = -0.0 ; } printf("a: %f, b: %f\n", a, b) ; if(a == b) printf("equal\n"); else printf("unequal\n"); return 0;

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 41 $ cc -Wall twozeros.c $ a.out a: 0.000000, b: -0.000000 Equal

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 42 Largest +1 = The 32-bit pattern for infinity is 0 1111 1111 000 0000 0000 0000 0000 0000 The largest 32-bit normalized number is 0 1111 1110 111 1111 1111 1111 1111 1111 If we treat the largest normalized number as an int data and add one to it, we get.