Programming and Graphics

(Kiana) #1

20 Introduction to C++ Programming and Graphics


When the exponent takes a value that is higher than the maximum value
or lower than the minimum value that can be described with the available
number of bits, the operating system sends a message (exception) of system
overflow or underflow. Improper operations, such as dividing zero by zero or
computing the square root of a negative number, activate theNot-a-Number
(NaN)warning.


Precision


The number of bytes assigned to a real variable (word length) is controlled
by the programmer through the option of single, double, and extended precision.
A variable can be declared either as integer, in which case the binary point is
fixed at the end of the word length, or as real (floating-point) in which case the
binary point floats across the word-length.


Single precision


Single precision reserves 32-bit (4-byte) word lengths. A real number
in the range 1–2 can be resolved up to only the eighth decimal place, and
the machine accuracy is 10−^8. The mantissa is usually described by 23 bits,
and the biased exponent is described by 8 bits. System overflow or underflow
typically occurs when the absolute value of the exponent is higher than 127. The
maximum and minimum positive numbers that can be stored are 1. 701 × 1038
and 5. 877 × 10 −^39.


As an example, we consider the floating-point representation:

0 011 1111 1000 0000 0000 0000 0000 0000 (35)

The first bit specifies the sign, the bold-faced digits represent the exponent
shifted by 127, and the rest of the bits represent the mantissa. We note that
the binary string of 127 is precisely equal to the bold-faced sequence, and find
that the exponent is zero. We recall the implicit presence of a hidden bit and
the convection that a zero sign bit corresponds to the plus sign, and find that
this floating point string represents the number 1.0.


Double precision


Double precision reserves 64-bit (8-byte) word lengths. A real number
in the range 1–2 can be resolved up to the fourteenth or sixteenth decimal
place. The mantissa is usually described by 52 bits, and the biased exponent
is described by 11 bits. System overflow or underflow typically occurs when
the absolute value of the exponent is higher that 1023, and the maximum and
minimum positive numbers that can be stored are 8. 988 × 10307 and 1. 123 ×
10 −^308.

Free download pdf