home *** CD-ROM | disk | FTP | other *** search
- 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
- From: mhiroshi@tansei.cc.u-tokyo.ac.jp (H. Murakami)
- Newsgroups: comp.unix.bsd
- Subject: [386bsd] vfprintf routine's trouble.
- Message-ID: <3862@tansei1.tansei.cc.u-tokyo.ac.jp>
- Date: 10 Jan 93 01:30:06 GMT
- Sender: news@tansei.cc.u-tokyo.ac.jp
- Organization: Hokkaido Univ. However I am subject to tansei for JUNET.
- Lines: 50
-
-
-
- % cat a.c
- /*
- * This demonstrates a not so important flaw
- * in the vfprintf rountine of 386bsd0.1
- * when printing the extremal value.
- * This is detected by the warning messages of the enquire.c
- */
- #include <math.h>
-
- main()
- {
- double x;
- static double y;
- int *iy = (int *) &y;
- char t[128]; char *sx;
-
- /* 2^(-1022): the smallest normalized double. */
- x = ldexp(1.0,-1022);
- /* sx is the over-precision value of x. */
- sx = "2.22507385850720138e-308";
-
- sprintf(t, "%.15le", x);
- sscanf(t, "%le", &y);
- printf("%s\n%08x %08x\n\n", t, iy[0], iy[1], y);
-
- sprintf(t, "%.16le", x);
- sscanf(t, "%le", &y);
- printf("%s\n%08x %08x\n\n", t, iy[0], iy[1], y);
-
- sscanf(sx, "%le", &y);
- printf("%s\n%08x %08x\n\n", sx, iy[0], iy[1], y);
-
- }
- %
- %
- % gcc a.c
- % a.out
- 2.225073858507201e-308
- 00000000 00100000 << THIS IS THE CORRECT BIT PATTERN OF 2^(-1022).
-
- 2.2250738585072010e-308 << same value except the last wrong digit of zero.
- ffffffff 000fffff << THIS IS A LITTLE BIT SHORT (wrong).
-
- 2.22507385850720138e-308
- 00000000 00100000 << THIS IS THE CORRECT BIT PATTERN.
- %
- %
- %
-