Title: Handling Real Numbers Fractions
1Handling Real Numbers / Fractions
- Two types of real numbers are in use
- 1) Fixed Point Numbers
- e.g. 12.36 (Decimal) , 34.AD (HEX)
- -1110.11 (Binary) , 273.0 (Octal)
- 2) Floating Point Numbers
- e.g. 12.367 e 05(Decimal) gt -12.367 X 10 05
- 0.000011 e 1101 (Binary) gt 0.000011 X 2
(-1101) - A23.B5 e AD (Hex) gt A23.B5 X 16 AD
- 23467.0008e124 (Octal) gt 23467.0008 X 8 124
-
2Fixed Point Real Numbers (Salient Features)
- General format
- ltSigngt ltInteger Partgt / 0 . ltFractional Partgt
/ 0 - ltRadix Point /
Periodgt - Sign may be absent (Unsigned ) assumed positive.
- Fixed position of Radix Point / Period separates
Integer Part from the Fractional part. - Integer Part and/or Fractional Part can be 0.
- Signed Magnitude scheme of representation is used
because of the possible infinite precision of the
fractional part.
3Fixed Point Real Numbers (Salient Features) - 2
- Example
- 12.354 (Decimal) is interpreted in the
following way - Integer Part 12 (Unsigned) 1X10(2-1) 2 X 10
(1-1) - Fractional Part 354 3X 10 (-1) 5 X 10 (-2)
4 X 10 (-3) - -111.1101 (Binary) is interpreted in the
following way - Integer part -111 (-ve) 1 X 2 (2) 1 X 2 (1)
1 X 2 (0) - Fractional Part 1101 1 X 2 (- 1) 1 X 2(- 2)
1 X 2 (- 3) - A2.B3 (Hex) is interpreted in the following way
- Integer Part A2 (ve ) A 10 X 16 (1) 2 X
16 (0) - Fractional Part B3 B 11 X 16 (-1) 3 X 16
(-2)
4Floating Point Real Numbers (Salient Features) -
1
- General format
- ltSigngt lt Fixed Point Real Significand /
Mantissa gt - e ltexp. Signgt lt
Integer Exponent gt. - Sign / exp. Sign both may be absent (Unsigned )
assumed positive in both cases. - Convenient way to represent too small or too
large a number - e.g. 0.000000012 (Decimal) gt 0.12 e 07
- 1111 1111 1111 1111 (Binary) gt 1.11 e
1111
5Floating Point Real Numbers (Salient Features) -
2
- Examples
- 1.234 e 55 (Decimal) interpreted as
- Significand / Mantissa 1.234
- Exponent 55 gt 10 55 1.234 X 10 55
- 1234000..000 (51 Zeroes) in Total
- 1101.111 e - 101 (Binary) interpreted as
- Significand / Mantissa 1101 .111 (ve)
- Exponent -101 gt 2 -101(Binary) -5(Decimal)
- 1101.111 X 2 (- 5) gt 0.01101111(Binary)
6Floating Point Real Numbers (Salient Features) -
3
- Example (Contd.)
- - 0.637 e - 06 (Octal) interpreted as
- Significand / Mantissa -0.637
- Exponent - 26 gt 8 -06 (Octal) -6 ( Decimal
) - - 0.637 X 8 (- 6) gt - 0.000000637(Octal)
- Position of the radix point / period floats
within the Significand depending on the value
(weight) of the exponent. - e.g. 110.1111 e 101 (Binary) gt 0.1101111 e 1000
- gt 1101111.0 e 001 gt 1101.111 e 100
- -123.45 e -20 (Decimal) gt -0.12345 e -17 gt
-1234.5 e -21
7Signed Real Numbers (Representation Issues) - 1
- Representation of Fixed Point Numbers .
- a) Representation Format.
- b) Isolation of Integer Fractional Parts.
- Representation of Floating Point Numbers.
- i) Representing Fixed Point Significand /
Mantissa. - ii) Representing signed Integer Exponent.
- Choice of
- a) Universal representation format.
- b) Compact , machine compatible
representation format. - Measure of accuracy / limitations of the chosen
- representation format.
8Signed Real Numbers (Representation Issues) - 2
- Salient Observations
- 1) Fractional Part size is NOT Fixed, hence
preferred representation scheme for fixed point
values has to be Signed Magnitude one with
Leading / Leftmost 0 -gt ve Sign Leading (r-1)
digit in base/radix r -gt -ve sign. - 2) Fractional Part may needed to be either
Truncated or Rounded Off in order to represent
within Finite Word Size of a machine. - 3) Floating Point provides a choice of
universatility as well as compactness. - e.g. ( Sign Magnitude with sign represented as
digit ) - 123.45 (Decimal) gt 0 1.2345 e 02 gt 0
0.12345 e 03 - - 111.0 (Binary) gt 1 1.11 e 010 gt 1
0.111 e 011 - - 345.47 e - 08(Octal) gt 7 3.4547 e -06
gt 7 0.34547 e - 05 - - 2.3A8 e 01 (Hex) gt F 2.3A8 e 01 gt F
0.23A8 e 02
9Signed Real Numbers (Representation Issues) - 3
- Compact Representation of Fixed Point
Significand / Mantissa Normalized Significand
/Mantissa One of the two following ways may be
adopted - 1) Single Digit Integer Part The format of
representation being s d.dddd.. where s is
the sign and d is any digit in the relevant
base . Here the integer part consists of a single
Non Zero digit. In some cases the Integer Part
may be implied. - 2) Purely Fraction The format of
representation being - s 0.dddd.. Here again s is the sign and d
is any digit in the relevant base with the
leftmost digit being NON Zero. In this case one
can always assume a 0 integer part or alternately
an implied integer part. - N.B In both cases the isolation between Integer
Part Fractional Parts are achieved as a by-
product i.e. no special isolation techniques are
needed.
10Signed Real Numbers (Representation Issues) - 4
- Representation of Signed Integer Exponent
- Two choices
- 1) rs Complement Scheme One need to have
two types of processing circuits Signed Magnitude
for handling Significand /Mantissa rs
Complement for processing Exponents may not be
economical. - 2) Biased Scheme Here one adds a fixed bias
value B to the actual exponent Ae to convert it
to a biased exponent Be. The choice of the bias
value B is done in the following manner - Be AeB 0 when Actual Bias Ae is the
maxm. ve - e.g. For decimal base maxm. ve Exponent (Ae)
-99 hence the Bias value chosen B 99
11Signed Real Numbers (Representation Issues) - 5
- Examples
- 123.45 (Decimal) gt 0 1.2345 e 02 gt 0
1.2345 e 101 - OR gt 0 0.12345 e 102 After
adding Bias 99 (Decimal) - - 111.0 (Binary) gt 1 1.11 e 010 gt 1
1.11 e 110 - OR gt 1 0.111 e 111 After
adding Bias 100 (Binary) - - 345.47 e - 08(Octal) gt 7 3.4547 e -06
gt 7 3.4547 e 71 - OR gt 7 0.34547 e 72 After
adding Bias 77 (Octal) -
- - 2.3A8 e 01 (Hex) gt F 2.3A8 e 01 gt F
2.3A8 e 100 - OR gt F 0.23A8 e 101 After adding
Bias FF (Hex)
12Signed Real Numbers (Representation Issues) - 6
- Conversion Steps
- ( Normalized Mantissa , Biased Exponent )
- 1) Represent the Real Number in Floating Point
Notation (Signed Magnitude Form). - 2) Normalize the Mantissa / Significand (
normally into 0.dddd..) form by adjusting the
Exponent. - 3) Add specified bias to this adjusted
Exponent. - 4) Check for Overflow / Underflow ( to be
elaborated later).
13Signed Real Numbers (Representation Issues) - 7
- Range Precision
- Range dependent on Exponent
- The value range of any n-digit exponent
happens to be - -(rn 1). (rn 1) in base r.
- After biasing the range changes to 0 2(rn
1) . Its size may also increase by at least one
more digit. - Increasing the number of digits in the exponent
size - increases the range.
- 2) Precision dictated by the Size of the
Mantissa/ Significand - More number of digits in the Mantissa/Significan
d helps to increase the precision. -
14Signed Real Numbers (Representation Issues) - 8
- Illustration of Range Precision
- Mantissa/ Significand 0. dddddddd max 8
digits. - Unbiased Exponent 2 digits / 4 bit binary
(with sign) . - 1) Decimal (base 10) Bias 99 , biased
range 100..10198 - Precision 8 digit long.
- 2) Binary (base 2) Bias 1000 , biased
range 2 0..2 1111 binary - (biased version can be obtained by
inverting the MSBit of the Exponent) . Precision
8 bit long. - 3) Octal (base 8) Bias 77 , biased range
8 0..8 176 Octal - Precision 8 digit long.
- 4) Hex (base 16) Bias FF , biased range
160..16100 Hex - Precision 8 digit long.
15Signed Real Numbers (Representation Issues) - 9
- Overflow Under Flow cases ( Example)
- Decimal 8 digit Normalized 0.ddd..
Significand , 3 digit biased Expont - Largest ? 0.99999999 X 10 198 represented as
0/9 99999999 e 198 - Smallest ? 0.1 X 10 0 represented as 0/9
10000000 e 000 - Now consider representing ? d.0 X 10 198 where d
represents any non zero digit . Clearly if we
want to normalize the mantissa , the exponent
will go beyond the specified range. Exponent
Overflow . - Again one cannot represent ? 0.0d X 10 0 where d
represents any non zero digit . Clearly if we
want to normalize the mantissa , the exponent
will go below the specified range. Exponent
Underflow .
16IEEE 754 standard for representing binary Real
Numbers - 1
- Significand / Mantissa
- Format 0/1 1.dddd..
- The integer part (1.) is always implied except
for Zero - -ZERO
- Leftmost bit of the fractional part need not be
non zero. - Size of the Significand may be one of the
following - Size in bits Type of Value
- -------------------------------------------------
- 23 Single Precision
- 52 Double Precision
- 63 Extended
Precision
17IEEE 754 standard for representing binary Real
Numbers - 2
- Biased Exponent
- Size of the Biased Exponent may be one of the
following - Size in bits Biased Exponent Range
Type of Value - --------------------------------------------------
------------------------------- - 8 1 - 255
Single Precision - 11 1 - 2047
Double Precision - 15 1 2047 X 16
Extended Precision
18IEEE 754 Single Precision Floating Point Number (
Salient Features )
- a) NaN (Not a Number ) Exceeds Significant
Precision - X 11111111 1. ltAny Valuegt
- ltSigngt lt8 bit Biased Exp.gt lt Impliedgt lt 23
bits Mantissa gt - NaN ltAny Operatorgt Any Value gt NaN
- b) Positive Values
- i) ? ( ve Infinity) Any further Processing
may yield ? OR NaN - 0 11111111 1. 0000000..0
Binding Upper Limit - ltSigngt lt8 bit Biased Exp.gt lt Impliedgt lt 23
bits Mantissa gt - ii) Ve Normalized 0 11111110 ? 00000001
1. 11..1 ?00..00 -
lt 8 bit Exponent Range gt lt
Mantissa Rangegt - iii) Ve De-Normalized 0 00000000 0.
11..1 ? 00..01 -
lt 8 bit Exponentgt lt Mantissa Rangegt -
19IEEE 754 Single Precision Floating Point Number
(Salient Features) -2
- c) Zero 0 00000000 0. 000000000
- d) Zero 1 00000000 0. 000000000
- e) Negative Values
- i) -Ve De-Normalized 1 00000000 0.
11..1 ? 00..01 -
lt 8 bit Exponentgt lt Mantissa Rangegt - ii) -Ve Normalized 1 11111110 ? 00000001
1. 11..1 ? 00..00 -
lt 8 bit Exponent Range gt lt
Mantissa Rangegt - iii) -? ( - ve Infinity)
- 1 11111111 1. 0000000..0
Binding Lower Limit - ltSigngt lt8 bit Biased Exp.gt lt Impliedgt lt 23
bits Mantissa gt
20IEEE 754 Floating Point Number (Common Features)
- A) Rounding Modes of the Significand
- i) Round towards ? ( for ve values)
- ii) Round towards ? ( for ve values).
- iii) Truncate ( for ANY value).
- iv) Round to the nearest even (for ANY value) .
21IEEE 754 Floating Point Number (Common Features)
- 2
- B) Usage of De Normalized Numbers
- 0 / 1 00000000..00 0.
11..1 ? 00..01 - ltSigngt lt Exponentgt lt
Impliedgt lt Mantissa Rangegt - 1) Enables the machine to handle small magnitude
numbers ( values nearer to zero) more
predictably. - 2) During processing some intermediate values
may become De Normalized momentarily which
otherwise may force one to abandon processing in
the middle. - C) Separate processing units along with
dedicated processing instructions normally exist
in all modern day CPU (as a Co-processor part)
to handle real values. -