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

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!brunix!brunix!rca
  3. From: rca@cs.brown.edu (Ronald C. Antony)
  4. Subject: Re: printf g format still broken under NeXTSTEP 3.0 
  5. Message-ID: <1992Nov11.095957.22979@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown University Department of Computer Science
  8. References: <1992Nov11.012228.23372@access.usask.ca>
  9. Date: Wed, 11 Nov 1992 09:59:57 GMT
  10. Lines: 80
  11.  
  12. In article <1992Nov11.012228.23372@access.usask.ca> eric@skatter.usask.ca writes:
  13. >I reported this bug in December 1989, and when NeXTSTEP 2.0 came out,
  14. >and when NeXTSTEP 2.1 arrived, and now that NeXTSTEP 3.0 has arrived ...
  15. >IT STILL ISN'T FIXED!!!!!
  16. >
  17. >Here's an example program:
  18. >
  19. >#include <stdio.h>
  20. >int
  21. >main (int argc, char **argv)
  22. >{
  23. >    int i, d;
  24. >    double x, y;
  25. >
  26. >    y = 3.141592654;
  27. >    for (i = 0, d = 1 ; i < 5 ; i++, d *= 10) {
  28. >        x = y / d;
  29. >        printf ("%12g %12.1g %12.2g %12.3g %12.4g\n", x, x, x, x, x);
  30. >    }
  31. >    return (0);
  32. >}
  33. >
  34. >Here's what *should* print (according to the ANSI standard).  And it *does*
  35. >print this on our SUN 4.1.2, and HP-UX V8, systems:
  36. >     3.14159            3          3.1         3.14        3.142
  37. >    0.314159          0.3         0.31        0.314       0.3142
  38. >   0.0314159         0.03        0.031       0.0314      0.03142
  39. >  0.00314159        0.003       0.0031      0.00314     0.003142
  40. > 0.000314159       0.0003      0.00031     0.000314    0.0003142
  41. >
  42. >And here's what the NeXT produces:
  43. >    3.141593          3.1         3.14        3.142       3.1416
  44. >    0.314159          0.3         0.31        0.314       0.3142
  45. >    0.031416            0         0.03        0.031       0.0314
  46. >    0.003142            0            0        0.003       0.0031
  47. >    0.000314            0            0            0       0.0003
  48. >
  49. >For the umpteenth time, NeXT:
  50. >1. The precision specifier for %g format is supposed to set the number of
  51. >   significant digits in the printed number.
  52. >
  53. >2. Non-zero digits to the left of the decimal point *do* count towards
  54. >   the number of significant digits (see the first line of the tables).
  55. >
  56. >3. Leading zeroes do not count towards the number of significant digits,
  57. >   even when they are to the right of the decimal point (see the last
  58. >   three lines of the tables).
  59.  
  60. Well, not to protect NeXT in regards to sleeping over important bug
  61. reports (sometimes I also wonder how they set the priorities, altough
  62. certainly nobody could claim they are otherwise lazy), I still wonder
  63. if they are not right. Maybe there are just two opinions what ANSI-C
  64. is supposed to do.
  65.  
  66. The C-Bible "The C Programming Language" by K+R, 2nd edition, ANSI-C
  67. states the following on page 244:
  68.  
  69. f    double; decimal notation of the form [-]mmm.ddd, where the
  70.     d's is specified by the precision. The default precision is 6;
  71.     a precision of ) suppresses the decimal point.
  72.  
  73. e,E    double; decimal notation of the form [-]m.dddddd e[+-]xx or
  74.     [-]mdddddd E[+-]xx, where the number of d's is specified by
  75.     the precision. The default precision is 6; a precision of 0
  76.     suppresses the decimal point.
  77. g,G    double; %e or %E is used if the exponent is less than -4 or
  78.     greater than or equal to the precision; otherwise %f is used.
  79.     Trailing zeros and a trailing decimal point are not printed.
  80.  
  81.  
  82. Now if they got it right, NeXT got it right. If K+R got it wrong,
  83. well, then NeXT should correct the bug and tell Prentice Hall to
  84. correct their bug as well.
  85.  
  86. Ronald
  87.  
  88. ------------------------------------------------------------------------------
  89. "The reasonable man adapts himself to the world; the unreasonable one persists
  90. in trying to adapt the world to himself. Therefore all progress depends on the
  91. unreasonable man."   G.B. Shaw   |  rca@cs.brown.edu or antony@browncog.bitnet
  92.