6 付録

実数の表現方法を確認するプログラムを載せておく.
   1 #include <stdio.h>
   2 
   3 int main(void){
   4   double f;
   5   char *a;
   6 
   7   f=12.8;
   8 
   9   a=(char *)&f;
  10 
  11   printf("%p\t%x\n",a,(unsigned char)*a);
  12   printf("%p\t%x\n",a+1,(unsigned char)*(a+1));
  13   printf("%p\t%x\n",a+2,(unsigned char)*(a+2));
  14   printf("%p\t%x\n",a+3,(unsigned char)*(a+3));
  15   printf("%p\t%x\n",a+4,(unsigned char)*(a+4));
  16   printf("%p\t%x\n",a+5,(unsigned char)*(a+5));
  17   printf("%p\t%x\n",a+6,(unsigned char)*(a+6));
  18   printf("%p\t%x\n",a+7,(unsigned char)*(a+7));
  19 
  20   printf("%60.55f\n",f);
  21 
  22 
  23   return 0;
  24 }
\fbox{実行結果}
0xbf909928      9a
0xbf909929      99
0xbf90992a      99
0xbf90992b      99
0xbf90992c      99
0xbf90992d      99
0xbf90992e      29
0xbf90992f      40
  12.8000000000000007105427357601001858711242675781250000000



ホームページ: Yamamoto's laboratory
著者: 山本昌志
Yamamoto Masashi
2006-02-06


no counter