|
|
coherent
float C Keyword float
Data type
Floating point numbers are a subset of the real numbers. Each
has a built-in radix point (or ``decimal point'') that shifts, or
``floats'', as the value of the number changes. It consists of
the following: one sign bit, which indicates whether the number
is positive or negative; bits that encode the number's _e_x_p_o_n_e_n_t;
and bits that encode the number's _f_r_a_c_t_i_o_n, or the number upon
which the exponent works. In general, the magnitude of the num-
ber encoded depends upon the number of bits in the exponent,
whereas its precision depends upon the number of bits in the
fraction.
The exponent often uses a bias. This is a value that is sub-
tracted from the exponent to yield the power of two by which the
fraction will be increased.
Floating point numbers come in two levels of precision: single
precision, called floats; and double precision, called doubles.
With most microprocessors, sizeof(float) returns four, which in-
dicates that it is four chars (bytes) long, and sizeof(double)
returns eight.
Several formats are used to encode floats, including IEEE,
DECVAX, and BCD (binary coded decimal). COHERENT uses DECVAX
format throughout.
The following describes DECVAX, IEEE, and BCD formats, for your
information.
***** DECVAX Format *****
The 32 bits in a float consist of one sign bit, an eight-bit ex-
ponent, and a 24-bit fraction, as follows. Note that in this
diagram, `s' indicates ``sign'', `e' indicates ``exponent'', and
`f` indicates ``fraction'':
ZDDDDDDDDDDD?
| seee eeee | Byte 4
CDDDDDDDDDDD4
| efff ffff | Byte 3
CDDDDDDDDDDD4
| ffff ffff | Byte 2
CDDDDDDDDDDD4
| ffff ffff | Byte 1
@DDDDDDDDDDDY
The exponent has a bias of 129.
If the sign bit is set to one, the number is negative; if it is
set to zero, then the number is positive. If the number is all
COHERENT Lexicon Page 1
float C Keyword float
zeroes, then it equals zero; an exponent and fraction of zero
plus a sign of one (``negative zero'') is by definition not a
number. All other forms are numeric values.
The most significant bit in the fraction is always set to one and
is not stored. It is usually called the ``hidden bit''.
The format for doubles simply adds another 32 fraction bits to
the end of the float representation, as follows:
ZDDDDDDDDDDD?
| seee eeee | Byte 8
CDDDDDDDDDDD4
| efff ffff | Byte 7
CDDDDDDDDDDD4
| ffff ffff | Byte 6
CDDDDDDDDDDD4
| ffff ffff | Byte 5
CDDDDDDDDDDD4
| ffff ffff | Byte 4
CDDDDDDDDDDD4
| ffff ffff | Byte 3
CDDDDDDDDDDD4
| ffff ffff | Byte 2
CDDDDDDDDDDD4
| ffff ffff | Byte 1
@DDDDDDDDDDDY
***** IEEE Format *****
The IEEE encoding of a float is the same as that in the DECVAX
format. Note, however, that the exponent has a bias of 127,
rather than 129.
Unlike the DECVAX format, IEEE format assigns special values to
several floating point numbers. Note that in the following
description, a tiny exponent is one that is all zeroes, and a
huge exponent is one that is all ones:
* A tiny exponent with a fraction of zero equals zero, regard-
less of the setting of the sign bit.
* A huge exponent with a fraction of zero equals infinity,
regardless of the setting of the sign bit.
* A tiny exponent with a fraction greater than zero is a denor-
malized number, i.e., a number that is less than the least
normalized number.
* A huge exponent with a fraction greater than zero is, by
definition, not a number. These values can be used to handle
special conditions.
COHERENT Lexicon Page 2
float C Keyword float
An IEEE double, unlike DECVAX format, increases the number of ex-
ponent bits. It consists of a sign bit, an 11-bit exponent, and
a 53-bit fraction, as follows:
ZDDDDDDDDDDD?
| seee eeee | Byte 8
CDDDDDDDDDDD4
| eeee ffff | Byte 7
CDDDDDDDDDDD4
| ffff ffff | Byte 6
CDDDDDDDDDDD4
| ffff ffff | Byte 5
CDDDDDDDDDDD4
| ffff ffff | Byte 4
CDDDDDDDDDDD4
| ffff ffff | Byte 3
CDDDDDDDDDDD4
| ffff ffff | Byte 2
CDDDDDDDDDDD4
| ffff ffff | Byte 1
@DDDDDDDDDDDY
The exponent has a bias of 1,023. The rules of encoding are the
same as for floats.
***** BCD Format *****
The BCD format (``binary coded decimal'', also called ``packed
decimal'') is used to eliminate rounding errors that alter the
worth of an account by a fraction of a cent. It consists of a
sign, an exponent, and a chain of four-bit numbers, each of which
is defined to hold the values zero through nine.
A BCD float has a sign bit, seven bits of exponent, and six four-
bit digits. In the following diagrams, `d' indicates ``digit'':
ZDDDDDDDDDDD?
| seee eeee | Byte 4
CDDDDDDDDDDD4
| dddd dddd | Byte 3
CDDDDDDDDDDD4
| dddd dddd | Byte 2
CDDDDDDDDDDD4
| dddd dddd | Byte 1
@DDDDDDDDDDDY
A BCD double has a sign bit, 11 bits of exponent, and 13 four-bit
digits, as follows:
COHERENT Lexicon Page 3
float C Keyword float
ZDDDDDDDDDDD?
| seee eeee | Byte 8
CDDDDDDDDDDD4
| eeee dddd | Byte 7
CDDDDDDDDDDD4
| dddd dddd | Byte 6
CDDDDDDDDDDD4
| dddd dddd | Byte 5
CDDDDDDDDDDD4
| dddd dddd | Byte 4
CDDDDDDDDDDD4
| dddd dddd | Byte 3
CDDDDDDDDDDD4
| dddd dddd | Byte 2
CDDDDDDDDDDD4
| dddd dddd | Byte 1
@DDDDDDDDDDDY
Passing the hexadecimal numbers A through F in a digit yields un-
predictable results.
The following rules apply when handling BCD numbers:
* A tiny exponent with a fraction of zero equals zero.
* A tiny exponent with a fraction of non-zero indicates a denor-
malized number.
* A huge exponent with a fraction of zero indicates infinity.
* A huge exponent with a fraction of non-zero is, by definition,
not a number; these non-numbers are used to indicate errors.
***** See Also *****
C keywords, data formats, double
_T_h_e _A_r_t _o_f _C_o_m_p_u_t_e_r _P_r_o_g_r_a_m_m_i_n_g, vol. 2, page 180_f_f
COHERENT Lexicon Page 4
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.