home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / next / programm / 7133 < prev    next >
Encoding:
Text File  |  1992-11-10  |  2.3 KB  |  64 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!think.com!ames!elroy.jpl.nasa.gov!decwrl!access.usask.ca!news
  3. From: eric@skatter.usask.ca
  4. Subject: printf g format still broken under NeXTSTEP 3.0 
  5. Message-ID: <1992Nov11.012228.23372@access.usask.ca>
  6. Sender: news@access.usask.ca (USENET News System)
  7. Nntp-Posting-Host: skatter.usask.ca
  8. Organization: University of Saskatchewan
  9. Date: Wed, 11 Nov 1992 01:22:28 GMT
  10. Lines: 52
  11.  
  12. I reported this bug in December 1989, and when NeXTSTEP 2.0 came out,
  13. and when NeXTSTEP 2.1 arrived, and now that NeXTSTEP 3.0 has arrived ...
  14. IT STILL ISN'T FIXED!!!!!
  15.  
  16. Here's an example program:
  17.  
  18. #include <stdio.h>
  19. int
  20. main (int argc, char **argv)
  21. {
  22.     int i, d;
  23.     double x, y;
  24.  
  25.     y = 3.141592654;
  26.     for (i = 0, d = 1 ; i < 5 ; i++, d *= 10) {
  27.         x = y / d;
  28.         printf ("%12g %12.1g %12.2g %12.3g %12.4g\n", x, x, x, x, x);
  29.     }
  30.     return (0);
  31. }
  32.  
  33. Here's what *should* print (according to the ANSI standard).  And it *does*
  34. print this on our SUN 4.1.2, and HP-UX V8, systems:
  35.      3.14159            3          3.1         3.14        3.142
  36.     0.314159          0.3         0.31        0.314       0.3142
  37.    0.0314159         0.03        0.031       0.0314      0.03142
  38.   0.00314159        0.003       0.0031      0.00314     0.003142
  39.  0.000314159       0.0003      0.00031     0.000314    0.0003142
  40.  
  41. And here's what the NeXT produces:
  42.     3.141593          3.1         3.14        3.142       3.1416
  43.     0.314159          0.3         0.31        0.314       0.3142
  44.     0.031416            0         0.03        0.031       0.0314
  45.     0.003142            0            0        0.003       0.0031
  46.     0.000314            0            0            0       0.0003
  47.  
  48. For the umpteenth time, NeXT:
  49. 1. The precision specifier for %g format is supposed to set the number of
  50.    significant digits in the printed number.
  51.  
  52. 2. Non-zero digits to the left of the decimal point *do* count towards
  53.    the number of significant digits (see the first line of the tables).
  54.  
  55. 3. Leading zeroes do not count towards the number of significant digits,
  56.    even when they are to the right of the decimal point (see the last
  57.    three lines of the tables).
  58.  
  59. --
  60. Eric Norum                     eric@skatter.usask.ca
  61. Research Engineer              phone: (306) 966-6308
  62. Accelerator Laboratory
  63. University of Saskatchewan
  64.