CS 2734 Computer Organization II


Laboratory 13 [Dec 6, 8]
Floating Point Number Formats
(double in the IEEE standard)

For this laboratory, you are to experiment with the bit pattern used to represent a double by computers that adhere to the IEEE standard for doubles. (See text, Section 4.8, pages 275-280. Sun hardware follows the standard.)

Given either an "ordinary" floating point number or a bit pattern, it is easy to get the other representation, say, with a simple program like the following:

#include <stdio.h>
#include <ctype.h>
void main(void){
   union {
      double d; 
      struct {
         int p;
         int q;
      } b;   } r;
   char ch;
   for( ; ; ) {
      while (isspace(ch = getchar()))
         ;
      if (ch == 'x') {
         scanf("%x %x", &r.b.p, &r.b.q);
         printf("  Decimal: %20.16e\n", 
            r.d);
         printf("  Bits: %08x %08x\n",
            r.b.p, r.b.q);
      }
      else if (ch == 'f') {
         scanf("%lf", &r.d);
         printf("  Decimal: %20.16e\n",
            r.d);
         printf("  Bits: %08x %08x\n",
            r.b.p, r.b.q);
      }
      else break;
   }
}
Typical output looks like:
f 16.0
  Decimal: 1.6000000000000000e+01
  Bits: 40300000 00000000
f .75
  Decimal: 7.5000000000000000e-01
  Bits: 3fe80000 00000000
f 1.5
  Decimal: 1.5000000000000000e+00
  Bits: 3ff80000 00000000
x 3fe80000 00000000
  Decimal: 7.5000000000000000e-01
  Bits: 3fe80000 00000000
f -0.75
  Decimal: -7.5000000000000000e-01
  Bits: bfe80000 00000000
x bfffffff ffffffff
  Decimal: -1.9999999999999998e+00
  Bits: bfffffff ffffffff
For the actual laboratory work:


Revision Date: 4/28/99