home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / bsd / 11086 < prev    next >
Encoding:
Text File  |  1993-01-09  |  1.7 KB  |  61 lines

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!udel!gatech!swrinde!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!sun-barr!sh.wide!wnoc-tyo-news!news.u-tokyo.ac.jp!yayoi!tansei1!mhiroshi
  2. From: mhiroshi@tansei.cc.u-tokyo.ac.jp (H. Murakami)
  3. Newsgroups: comp.unix.bsd
  4. Subject: [386bsd] vfprintf routine's trouble.
  5. Message-ID: <3862@tansei1.tansei.cc.u-tokyo.ac.jp>
  6. Date: 10 Jan 93 01:30:06 GMT
  7. Sender: news@tansei.cc.u-tokyo.ac.jp
  8. Organization: Hokkaido Univ. However I am subject to tansei for JUNET.
  9. Lines: 50
  10.  
  11.  
  12.  
  13. % cat a.c
  14. /*
  15.  *  This demonstrates a not so important flaw 
  16.  *  in the vfprintf rountine of 386bsd0.1 
  17.  *  when printing the extremal value.
  18.  *  This is detected by the warning messages of the enquire.c
  19.  */
  20. #include <math.h>
  21.  
  22. main()
  23. {
  24.         double x; 
  25.         static double y;
  26.         int *iy = (int *) &y;
  27.         char t[128]; char *sx;
  28.         
  29.         /* 2^(-1022): the smallest normalized double. */
  30.         x = ldexp(1.0,-1022);  
  31.         /* sx is the over-precision value of x. */
  32.         sx = "2.22507385850720138e-308";
  33.  
  34.         sprintf(t, "%.15le", x);
  35.         sscanf(t, "%le", &y);
  36.         printf("%s\n%08x %08x\n\n", t, iy[0], iy[1], y);
  37.  
  38.         sprintf(t, "%.16le", x);
  39.         sscanf(t, "%le", &y);
  40.         printf("%s\n%08x %08x\n\n", t, iy[0], iy[1], y);
  41.  
  42.         sscanf(sx, "%le", &y);
  43.         printf("%s\n%08x %08x\n\n", sx, iy[0], iy[1], y);
  44.  
  45. }
  46. %
  47. %
  48. % gcc a.c
  49. % a.out
  50. 2.225073858507201e-308
  51. 00000000 00100000         << THIS IS THE CORRECT BIT PATTERN OF 2^(-1022).
  52.  
  53. 2.2250738585072010e-308   << same value except the last wrong digit of zero.
  54. ffffffff 000fffff         << THIS IS A LITTLE BIT SHORT (wrong).
  55.  
  56. 2.22507385850720138e-308
  57. 00000000 00100000         << THIS IS THE CORRECT BIT PATTERN.
  58. %
  59. %
  60. %
  61.