Sun (IEEE) Floating point format
Scott Leadley
leadley at cc.rochester.edu
Tue May 22 02:18:17 AEST 1990
In article <7914 at brazos.Rice.edu> pmeese at govt.shearson.com (Philip Meese 36743) writes:
>In response to the message from PRABAL at rcgl1.eng.ohio-state.edu (Prabal Acharyya)
>in V9-162:
>> Can anybody explain the binary format used by SUN OS 4.0.3 to represent
>> floating point numbers. I am trying to convert floating point numbers
>> from a Gould 32/77 machine to my SUN 4/330.
...
>SunOs uses standard IEEE floating point format. There are two variants:
>one for 4 byte numbers (floats) and one for 8 byte numbers (doubles). The
>format for floats escapes me right now but I could dig up my file on this
>if you you could use it. The 8 byte double format is:
>
> Starting length
> position in bits contents
> --------- ------- --------
> 1 1 sign bit
> 2 11 exponent
> 13 52 mantissa
>
>The ieee exponent is a decimal number biased by 0x3FF. In other words, add
Wrong polarity. The bias of 0x3FF should be subtracted from the exponent.
>0x3ff to the number stored there to get the real exponent. The exponent
>can be thought of as representing the number of nibbles to move the
>"binary point" to arrive at the final number.
A common Sun manual that may help is the _C Programmer's Guide_, Appendix
D, "Sun-2, -3, and -4 Data Representations" (PN 800-1771-10).
IEEE single precision (4 bytes)
3 3 2 2
1 0 3 2 0
+----------------------------------+
| | | |
+----------------------------------+
^ ^ ^
| exponent mantissa
sign bit
The exponent bias is 127 (0x7F).
IEEE double precision (8 bytes)
6 6 5 5
3 2 2 1 0
+------------------------------------------------------------------+
| | | |
+------------------------------------------------------------------+
^ ^ ^
| exponent(*) mantissa
sign bit
The exponent bias is 1023 (0x3FF).
(*) Table D-5 in the _C Programmer's Guide_ incorrectly states that
the exponent length is 8 bits (it is actually 11 bits).
A normalized floating point number represents the real number:
sign bit (exponent-bias)
(-1) * 2 * 1.mantissa
The "1." in front of the mantissa represents the "hidden bit" in
normalized numbers. I.e. the mantissa is stored with its most significant
bit (which is a 1 bit) removed.
Exponents of all 0s and all 1s are used to flag special representations:
sign bit exponent mantissa represents
-------- -------- -------- ----------
0 0 0 +0
1 0 0 -0
0 all ones 0 +Infinity
1 all ones 0 -Infinity
0 or 1 all ones non-zero NaN (Not-a-Number)
0 or 1 0 f denormalized number(*)
(*) a denormalized number is represents the real number:
sign bit (exponent-bias+1)
(-1) * 2 * 0.mantissa
NB. I have never had to deal with denormalized numbers and this
explanation is taken straight from the Sun manual with no judgement added.
Scott Leadley - leadley at cc.rochester.edu
More information about the Comp.sys.sun
mailing list