|
|
1.1 ! root 1: ! 2: ! 3: float C Keyword float ! 4: ! 5: ! 6: ! 7: ! 8: Data type ! 9: ! 10: ! 11: Floating point numbers are a subset of the real numbers. Each ! 12: has a built-in radix point (or ``decimal point'') that shifts, or ! 13: ``floats'', as the value of the number changes. It consists of ! 14: the following: one sign bit, which indicates whether the number ! 15: is positive or negative; bits that encode the number's _e_x_p_o_n_e_n_t; ! 16: and bits that encode the number's _f_r_a_c_t_i_o_n, or the number upon ! 17: which the exponent works. In general, the magnitude of the num- ! 18: ber encoded depends upon the number of bits in the exponent, ! 19: whereas its precision depends upon the number of bits in the ! 20: fraction. ! 21: ! 22: The exponent often uses a bias. This is a value that is sub- ! 23: tracted from the exponent to yield the power of two by which the ! 24: fraction will be increased. ! 25: ! 26: Floating point numbers come in two levels of precision: single ! 27: precision, called floats; and double precision, called doubles. ! 28: With most microprocessors, sizeof(float) returns four, which in- ! 29: dicates that it is four chars (bytes) long, and sizeof(double) ! 30: returns eight. ! 31: ! 32: Several formats are used to encode floats, including IEEE, ! 33: DECVAX, and BCD (binary coded decimal). COHERENT uses DECVAX ! 34: format throughout. ! 35: ! 36: The following describes DECVAX, IEEE, and BCD formats, for your ! 37: information. ! 38: ! 39: ***** DECVAX Format ***** ! 40: ! 41: The 32 bits in a float consist of one sign bit, an eight-bit ex- ! 42: ponent, and a 24-bit fraction, as follows. Note that in this ! 43: diagram, `s' indicates ``sign'', `e' indicates ``exponent'', and ! 44: `f` indicates ``fraction'': ! 45: ! 46: ! 47: ZDDDDDDDDDDD? ! 48: | seee eeee | Byte 4 ! 49: CDDDDDDDDDDD4 ! 50: | efff ffff | Byte 3 ! 51: CDDDDDDDDDDD4 ! 52: | ffff ffff | Byte 2 ! 53: CDDDDDDDDDDD4 ! 54: | ffff ffff | Byte 1 ! 55: @DDDDDDDDDDDY ! 56: ! 57: ! 58: The exponent has a bias of 129. ! 59: ! 60: If the sign bit is set to one, the number is negative; if it is ! 61: set to zero, then the number is positive. If the number is all ! 62: ! 63: ! 64: COHERENT Lexicon Page 1 ! 65: ! 66: ! 67: ! 68: ! 69: float C Keyword float ! 70: ! 71: ! 72: ! 73: zeroes, then it equals zero; an exponent and fraction of zero ! 74: plus a sign of one (``negative zero'') is by definition not a ! 75: number. All other forms are numeric values. ! 76: ! 77: The most significant bit in the fraction is always set to one and ! 78: is not stored. It is usually called the ``hidden bit''. ! 79: ! 80: The format for doubles simply adds another 32 fraction bits to ! 81: the end of the float representation, as follows: ! 82: ! 83: ! 84: ZDDDDDDDDDDD? ! 85: | seee eeee | Byte 8 ! 86: CDDDDDDDDDDD4 ! 87: | efff ffff | Byte 7 ! 88: CDDDDDDDDDDD4 ! 89: | ffff ffff | Byte 6 ! 90: CDDDDDDDDDDD4 ! 91: | ffff ffff | Byte 5 ! 92: CDDDDDDDDDDD4 ! 93: | ffff ffff | Byte 4 ! 94: CDDDDDDDDDDD4 ! 95: | ffff ffff | Byte 3 ! 96: CDDDDDDDDDDD4 ! 97: | ffff ffff | Byte 2 ! 98: CDDDDDDDDDDD4 ! 99: | ffff ffff | Byte 1 ! 100: @DDDDDDDDDDDY ! 101: ! 102: ! 103: ***** IEEE Format ***** ! 104: ! 105: The IEEE encoding of a float is the same as that in the DECVAX ! 106: format. Note, however, that the exponent has a bias of 127, ! 107: rather than 129. ! 108: ! 109: Unlike the DECVAX format, IEEE format assigns special values to ! 110: several floating point numbers. Note that in the following ! 111: description, a tiny exponent is one that is all zeroes, and a ! 112: huge exponent is one that is all ones: ! 113: ! 114: * A tiny exponent with a fraction of zero equals zero, regard- ! 115: less of the setting of the sign bit. ! 116: ! 117: * A huge exponent with a fraction of zero equals infinity, ! 118: regardless of the setting of the sign bit. ! 119: ! 120: * A tiny exponent with a fraction greater than zero is a denor- ! 121: malized number, i.e., a number that is less than the least ! 122: normalized number. ! 123: ! 124: * A huge exponent with a fraction greater than zero is, by ! 125: definition, not a number. These values can be used to handle ! 126: special conditions. ! 127: ! 128: ! 129: ! 130: COHERENT Lexicon Page 2 ! 131: ! 132: ! 133: ! 134: ! 135: float C Keyword float ! 136: ! 137: ! 138: ! 139: An IEEE double, unlike DECVAX format, increases the number of ex- ! 140: ponent bits. It consists of a sign bit, an 11-bit exponent, and ! 141: a 53-bit fraction, as follows: ! 142: ! 143: ! 144: ZDDDDDDDDDDD? ! 145: | seee eeee | Byte 8 ! 146: CDDDDDDDDDDD4 ! 147: | eeee ffff | Byte 7 ! 148: CDDDDDDDDDDD4 ! 149: | ffff ffff | Byte 6 ! 150: CDDDDDDDDDDD4 ! 151: | ffff ffff | Byte 5 ! 152: CDDDDDDDDDDD4 ! 153: | ffff ffff | Byte 4 ! 154: CDDDDDDDDDDD4 ! 155: | ffff ffff | Byte 3 ! 156: CDDDDDDDDDDD4 ! 157: | ffff ffff | Byte 2 ! 158: CDDDDDDDDDDD4 ! 159: | ffff ffff | Byte 1 ! 160: @DDDDDDDDDDDY ! 161: ! 162: ! 163: The exponent has a bias of 1,023. The rules of encoding are the ! 164: same as for floats. ! 165: ! 166: ***** BCD Format ***** ! 167: ! 168: The BCD format (``binary coded decimal'', also called ``packed ! 169: decimal'') is used to eliminate rounding errors that alter the ! 170: worth of an account by a fraction of a cent. It consists of a ! 171: sign, an exponent, and a chain of four-bit numbers, each of which ! 172: is defined to hold the values zero through nine. ! 173: ! 174: A BCD float has a sign bit, seven bits of exponent, and six four- ! 175: bit digits. In the following diagrams, `d' indicates ``digit'': ! 176: ! 177: ! 178: ZDDDDDDDDDDD? ! 179: | seee eeee | Byte 4 ! 180: CDDDDDDDDDDD4 ! 181: | dddd dddd | Byte 3 ! 182: CDDDDDDDDDDD4 ! 183: | dddd dddd | Byte 2 ! 184: CDDDDDDDDDDD4 ! 185: | dddd dddd | Byte 1 ! 186: @DDDDDDDDDDDY ! 187: ! 188: ! 189: A BCD double has a sign bit, 11 bits of exponent, and 13 four-bit ! 190: digits, as follows: ! 191: ! 192: ! 193: ! 194: ! 195: ! 196: COHERENT Lexicon Page 3 ! 197: ! 198: ! 199: ! 200: ! 201: float C Keyword float ! 202: ! 203: ! 204: ! 205: ZDDDDDDDDDDD? ! 206: | seee eeee | Byte 8 ! 207: CDDDDDDDDDDD4 ! 208: | eeee dddd | Byte 7 ! 209: CDDDDDDDDDDD4 ! 210: | dddd dddd | Byte 6 ! 211: CDDDDDDDDDDD4 ! 212: | dddd dddd | Byte 5 ! 213: CDDDDDDDDDDD4 ! 214: | dddd dddd | Byte 4 ! 215: CDDDDDDDDDDD4 ! 216: | dddd dddd | Byte 3 ! 217: CDDDDDDDDDDD4 ! 218: | dddd dddd | Byte 2 ! 219: CDDDDDDDDDDD4 ! 220: | dddd dddd | Byte 1 ! 221: @DDDDDDDDDDDY ! 222: ! 223: ! 224: Passing the hexadecimal numbers A through F in a digit yields un- ! 225: predictable results. ! 226: ! 227: The following rules apply when handling BCD numbers: ! 228: ! 229: * A tiny exponent with a fraction of zero equals zero. ! 230: ! 231: * A tiny exponent with a fraction of non-zero indicates a denor- ! 232: malized number. ! 233: ! 234: * A huge exponent with a fraction of zero indicates infinity. ! 235: ! 236: * A huge exponent with a fraction of non-zero is, by definition, ! 237: not a number; these non-numbers are used to indicate errors. ! 238: ! 239: ***** See Also ***** ! 240: ! 241: C keywords, data formats, double ! 242: _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 ! 243: ! 244: ! 245: ! 246: ! 247: ! 248: ! 249: ! 250: ! 251: ! 252: ! 253: ! 254: ! 255: ! 256: ! 257: ! 258: ! 259: ! 260: ! 261: ! 262: COHERENT Lexicon Page 4 ! 263: ! 264:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.