Tutorial 4
CSN 221
Floating Points Errors
How Computers Handle
Comparison
● More Concretely the Computer
Calculates the absolute
difference between the two and
if it is within the range of certain
epsilon the comparison is
assumed to be correct
● Higher the Bits for precision the
greater the subtraction would
be in the range of epsilon. The
example in last slide denoted
how the increase in bits lead to
a more precision and a
successful comparison
Integer Representation - Positive
NO
Positive NO:
For Positive No, Representation of the
positive no is same in all different
representation namely
Sign Magnitude, 1st Complement and 2nd
Complement
● For N bit no.. (1 Bit for sign
Representation and n-1 bit for no)
● Signed/1st complement -2^(n-1) to
2^(n-1)
● 2nd Complement -2^n to 2^(n-1)
Thus for Representing Positive no, one
simply write the no in binary format ensuring
a leading 0 at the MSB
Integer Representation - Negative NO
To convert the no in Negative Representation
1. Write the no in Positive representation ensuring MSB is 0
● Sign Magnitude :
○ Change the Sign of MSB
● 1st Complement
○ Invert each of the bits from 0 to 1 and 1 to 0 (Vice Versa)
● 2nd Complement
○ Invert each of the Bits like above and add 1 to LSB
To find the value : Do the same process again, find the value and add Negative
sign
Representation of 50 and -50 in Sign Magnitude 1st Complement
and 2nd Complement
The 16-bit 2’s complement representation of an integer is 1111 1111 1111 0101;
its decimal representation is
IEEE 754
● The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for
floating-point arithmetic established in 1985 by the Institute of Electrical and Electronics
Engineers (IEEE). The standard addressed many problems found in the diverse floating-point
implementations that made them difficult to use reliably and portably. Many hardware
floating-point units use the IEEE 754 standard.
● Thus 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. This explains the output we had in screenshot of c program
The decimal value 9.75 in IEEE single precision floating point
The decimal value 0.5 in IEEE single precision floating point
Take Home