Floating Point Numbers - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Floating Point Numbers

Description:

Let's assume that we have n bits to represent a real number. ... If e is the exponent then e b is stored as unsinged number for exponent. Numbers are normalized. ... – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 14
Provided by: rajat1
Category:

less

Transcript and Presenter's Notes

Title: Floating Point Numbers


1
Floating Point Numbers
  • Ajai Jain (ajain_at_iitk.ac.in)
  • Rajat Moona (moona_at_iitk.ac.in)

2
Real Numbers Fixed point
  • Lets assume that we have n bits to represent a
    real number.
  • If the position of the binary point is fixed (say
    4 locations from the right)
  • We do not need to store any information about the
    binary point.
  • Bit pattern 11101101 is 8-bit fixed point
    representation with implied binary point at
    fourth bit from the right.
  • This bit pattern is for 14.8125 in decimal
  • Same bit pattern when treated as unsigned number
    indicates 237.
  • In general a bit pattern for a fixed point number
    f is same as the bit pattern for a number f?2i,
    where i is the position of implied binary point.
  • Fixed point numbers can be signed or unsigned.
  • Precision 2-i
  • Range 2-i times the range of the corresponding
    integer.

3
Fixed point numbers
  • Advantage
  • Simple format Same as integer format
  • Simple algorithms Add/Subtract same as integer
    add/subtract.
  • Multiply and divide Integer multiply/divide
    followed by a bit shift.
  • Disadvantage
  • If the data set is large, one ends up having huge
    size of the data structure.
  • For example If a variable is needed to be able
    to store mass of a planet or mass of a person to
    a reasonable accuracy, it will have large number
    of bits for the integer part.

4
Scientific representation
  • Numbers in scientific representation are stored
    with significand and exponent.
  • Mass of an electron 9.1 ? 10-28g
  • Mass of a person 6.0 ? 104g
  • In standard (normalized form), significand is
    between 1.0, 10).
  • Zero can not be written as a number in normalized
    form.

5
Scientific numbers in binary
  • Exponents are powers of 2.
  • Significands are binary.
  • In normalized form, significand is between 1.0,
    2).
  • Integer part is always 1.xxxx
  • 1.0011E100 is 1.0011?2b100, or b10011, or 19.

6
Floating Point Numbers
  • Exponents can be positive or negative.
  • Exponents are stored as biased integer.
  • If e is the exponent then eb is stored as
    unsinged number for exponent.
  • Numbers are normalized.
  • Significand is of the form 1.xxxx
  • 1. need not be stored.

7
IEEE754 Single Precision numbers
  • Used by most programming languages as float
    data type.
  • 32 bit wide
  • Includes
  • Sign, Mantissa, Exponent
  • Sign Sign of the number
  • Mantissa Significand without leading 1.0
  • Exponent biased by 127 or excess-127.

8
IEEE754 Single precision numbers
0
31
30
23
22
S
Exp (excess-127)
Mantissa
Consider -24.75 in decimal. In Binary
-11000.11 Scientific Binary -1.100011 ? 24 Sign
1 (Negative) Exponent 4127 (131) or 10000011
in binary Mantissa 100011000000000000000000 Bit
pattern for IEEE754 1 10000011
100011000000000000000000 ? hC1C60000
9
Double precision numbers
  • 64 Bits in size.
  • Sign 1 bit
  • Exponent 11 bits excess-1023
  • Mantissa 52 bits
  • Can not represent 0.0 in this way.
  • There is no 1. prefix in its representation.
  • Real number computations also need 8.

10
Special Cases
  • 0.0 or -0.0
  • Sign 0 (for ), 1 (for -).
  • Exponent and Mantissa all zeros.
  • Bit pattern for an integer 0 is same as bit
    pattern for float 0.0.
  • 8
  • Sign 0 or 1 to indicate the sign of 8.
  • Exponent All 1s (0xFF for single precision.
    0x7FF for double precision)
  • Mantissa All 0s.

11
Special Cases
  • Not-A-Number (NaN)
  • Exponent all 1s. Mantissa Other than all zeros.
  • Denormalized numbers
  • Needed to store small intermediate results
  • Exponent all zeros. Mantissa Other than all
    zeros.
  • Assumed to be as
  • 0.m?21-b.

12
Limits
  • Max normalized value
  • Exponent 0xFE or 0x7FE (for single/double
    precision).
  • Or 2127 (Single precision), 21023 (double
    precision)
  • Mantissa 111.111
  • Significand close to 2 with assumed 1. prefix
  • Max value 2128 (single precision), 21024
    (double precision)
  • Min positive normalized values
  • Exponent 0x01 ? 2-126 (single), 2-1022 (double)
  • Mantissa 000000 or 1.0
  • Min. value 2-126 (SP), 2-1022 (DP)
  • Precision 2e-23 or 2e-52 (for SP and DP
    respectively)
  • Precision is relative to the number (exponent e)

13
Denormalized numbers
  • Min (positive) value
  • Mantissa 000001
  • Exponent 0000
  • 2-149 for Single Precision, 2-1074 for double.
  • Max (positive) value
  • Mantissa 111111 (or, 0.111111, 1.0)
  • Exponent 0000
  • 2-126 (SP), 2-1022 (DP)
Write a Comment
User Comments (0)
About PowerShow.com