home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / next / programm / 5791 < prev    next >
Encoding:
Text File  |  1992-08-25  |  4.0 KB  |  117 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!rpi!scott.skidmore.edu!psinntp!psinntp!juliet!news
  2. From: drew@fnbc.com (Drew Davidson)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Re: fmod BUG fixed in 3.0?
  5. Message-ID: <1992Aug25.144605.19099@fnbc.com>
  6. Date: 25 Aug 92 14:46:05 GMT
  7. References: <strobel.714703207@dirac>
  8. Sender: news@fnbc.com
  9. Reply-To: drew@fnbc.com
  10. Distribution: na
  11. Organization: First National Bank Of Chicago, Chicago IL, USA
  12. Lines: 103
  13.  
  14. In article <strobel.714703207@dirac> strobel@dirac.phys.washington.edu (Nicolas  
  15. Strobel) writes:
  16. > Feeding negative numbers into the NeXT fmod() (running 2.1) produces  
  17. incorrect
  18. > numbers! Is this fixed under 3.0?  Here's my test program:
  19. > #include <stdio.h>
  20. > #include <math.h>
  21. > main()
  22. > {
  23. >     double value=1.3333333333333;    /* This value is what a larger 
  24. >                        program, in which I discovered the
  25. >                        bug, uses */
  26. >     double exes[21];
  27. >     int i;
  28. >     for(i=0;i<13;i++){
  29. >         exes[i]= (double)(i-6);
  30. >     }
  31. >     exes[13] = -4.5;
  32. >     exes[14] = 4.5;
  33. >     exes[15] = -1.333333333;
  34. >     exes[16] = 1.333333333;
  35. >     exes[17] = 0.5;
  36. >     exes[18] = -0.5;
  37. >     exes[19] = -201.0;
  38. >     exes[20] = 201.0;
  39. >     
  40. >     for(i=0;i<21;i++){
  41. >         y = fmod(exes[i],value);
  42. >         printf("%f %% 1.3333333333 = %f\n",exes[i],y);
  43. >     }
  44. > }
  45. > On my NeXT (2.1OS) I get incorrect results:
  46. > -6.000000 % 1.3333333333 = 2.000000  <- should be -0.666667
  47. > -5.000000 % 1.3333333333 = 1.666667  <- should be -1.000000
  48. > -4.000000 % 1.3333333333 = 0.000000
  49. > -3.000000 % 1.3333333333 = -0.333333
  50. > -2.000000 % 1.3333333333 = 2.000000  <- should be -0.666667
  51. > -1.000000 % 1.3333333333 = 1.666667  <- should be -1.000000
  52. > 0.000000 % 1.3333333333 = 0.000000
  53. > 1.000000 % 1.3333333333 = 1.000000
  54. > 2.000000 % 1.3333333333 = 0.666667
  55. > 3.000000 % 1.3333333333 = 0.333333
  56. > 4.000000 % 1.3333333333 = 0.000000
  57. > 5.000000 % 1.3333333333 = 1.000000
  58. > 6.000000 % 1.3333333333 = 0.666667
  59. > -4.500000 % 1.3333333333 = -0.500000
  60. > 4.500000 % 1.3333333333 = 0.500000
  61. > -1.333333 % 1.3333333333 = 1.333333   <- should have minus sign
  62. > 1.333333 % 1.3333333333 = 1.333333
  63. > 0.500000 % 1.3333333333 = 0.500000
  64. > -0.500000 % 1.3333333333 = -0.500000  <- actually correct!
  65. > -201.000000 % 1.3333333333 = 1.666667 <- should be -1.000000
  66. > 201.000000 % 1.3333333333 = 1.000000
  67. > The value I'm using in the fmod is 4/3 which may explain why the -4 and -3
  68. > lines are correct (?). If you have 
  69. > exes[i] = (double)(i-6)+ (0.27*((double)i/13.0));
  70. > inside the do loop (to get some non-integer numbers), you get wrong results
  71. > for the negative numbers. I've cross-checked my results against a sparc, a  
  72. mips
  73. > machine, a DEC machine running ultrix and an IBM-3090 running AIX. 
  74. > Nick
  75. > strobel@dirac.phys.washington.edu 
  76.  
  77. From 3.0PR2:
  78. mayberry> test
  79. -6.000000 % 1.3333333333 = -0.666667
  80. -5.000000 % 1.3333333333 = -1.000000
  81. -4.000000 % 1.3333333333 = 0.000000
  82. -3.000000 % 1.3333333333 = -0.333333
  83. -2.000000 % 1.3333333333 = -0.666667
  84. -1.000000 % 1.3333333333 = -1.000000
  85. 0.000000 % 1.3333333333 = 0.000000
  86. 1.000000 % 1.3333333333 = 1.000000
  87. 2.000000 % 1.3333333333 = 0.666667
  88. 3.000000 % 1.3333333333 = 0.333333
  89. 4.000000 % 1.3333333333 = 0.000000
  90. 5.000000 % 1.3333333333 = 1.000000
  91. 6.000000 % 1.3333333333 = 0.666667
  92. -4.500000 % 1.3333333333 = -0.500000
  93. 4.500000 % 1.3333333333 = 0.500000
  94. -1.333333 % 1.3333333333 = -1.333333
  95. 1.333333 % 1.3333333333 = 1.333333
  96. 0.500000 % 1.3333333333 = 0.500000
  97. -0.500000 % 1.3333333333 = -0.500000
  98. -201.000000 % 1.3333333333 = -1.000000
  99. 201.000000 % 1.3333333333 = 1.000000
  100.  
  101. So it looks like it is fixed!
  102. --
  103. +--------------------------------+-------------------------------------------+
  104. |        Drew  Davidson          | "When you're jacked up on 3 pots of       |
  105. |         Software Guy           | coffee it's easy to make a mistake."      |
  106. | First National Bank of Chicago |             - Krantz and Stanely,         |
  107. |     drew@fnbc.com  (NeXTmail)  |               "Programming the 68000"     |
  108. +--------------------------------+-------------------------------------------+
  109.