home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!rpi!scott.skidmore.edu!psinntp!psinntp!juliet!news
- From: drew@fnbc.com (Drew Davidson)
- Newsgroups: comp.sys.next.programmer
- Subject: Re: fmod BUG fixed in 3.0?
- Message-ID: <1992Aug25.144605.19099@fnbc.com>
- Date: 25 Aug 92 14:46:05 GMT
- References: <strobel.714703207@dirac>
- Sender: news@fnbc.com
- Reply-To: drew@fnbc.com
- Distribution: na
- Organization: First National Bank Of Chicago, Chicago IL, USA
- Lines: 103
-
- In article <strobel.714703207@dirac> strobel@dirac.phys.washington.edu (Nicolas
- Strobel) writes:
- >
- > Feeding negative numbers into the NeXT fmod() (running 2.1) produces
- incorrect
- > numbers! Is this fixed under 3.0? Here's my test program:
- >
- > #include <stdio.h>
- > #include <math.h>
- >
- > main()
- > {
- > double value=1.3333333333333; /* This value is what a larger
- > program, in which I discovered the
- > bug, uses */
- > double exes[21];
- > int i;
- >
- > for(i=0;i<13;i++){
- > exes[i]= (double)(i-6);
- > }
- > exes[13] = -4.5;
- > exes[14] = 4.5;
- > exes[15] = -1.333333333;
- > exes[16] = 1.333333333;
- > exes[17] = 0.5;
- > exes[18] = -0.5;
- > exes[19] = -201.0;
- > exes[20] = 201.0;
- >
- > for(i=0;i<21;i++){
- > y = fmod(exes[i],value);
- > printf("%f %% 1.3333333333 = %f\n",exes[i],y);
- > }
- > }
- >
- > On my NeXT (2.1OS) I get incorrect results:
- >
- > -6.000000 % 1.3333333333 = 2.000000 <- should be -0.666667
- > -5.000000 % 1.3333333333 = 1.666667 <- should be -1.000000
- > -4.000000 % 1.3333333333 = 0.000000
- > -3.000000 % 1.3333333333 = -0.333333
- > -2.000000 % 1.3333333333 = 2.000000 <- should be -0.666667
- > -1.000000 % 1.3333333333 = 1.666667 <- should be -1.000000
- > 0.000000 % 1.3333333333 = 0.000000
- > 1.000000 % 1.3333333333 = 1.000000
- > 2.000000 % 1.3333333333 = 0.666667
- > 3.000000 % 1.3333333333 = 0.333333
- > 4.000000 % 1.3333333333 = 0.000000
- > 5.000000 % 1.3333333333 = 1.000000
- > 6.000000 % 1.3333333333 = 0.666667
- > -4.500000 % 1.3333333333 = -0.500000
- > 4.500000 % 1.3333333333 = 0.500000
- > -1.333333 % 1.3333333333 = 1.333333 <- should have minus sign
- > 1.333333 % 1.3333333333 = 1.333333
- > 0.500000 % 1.3333333333 = 0.500000
- > -0.500000 % 1.3333333333 = -0.500000 <- actually correct!
- > -201.000000 % 1.3333333333 = 1.666667 <- should be -1.000000
- > 201.000000 % 1.3333333333 = 1.000000
- >
- > The value I'm using in the fmod is 4/3 which may explain why the -4 and -3
- > lines are correct (?). If you have
- > exes[i] = (double)(i-6)+ (0.27*((double)i/13.0));
- > inside the do loop (to get some non-integer numbers), you get wrong results
- > for the negative numbers. I've cross-checked my results against a sparc, a
- mips
- > machine, a DEC machine running ultrix and an IBM-3090 running AIX.
- >
- > Nick
- > strobel@dirac.phys.washington.edu
-
- From 3.0PR2:
- mayberry> test
- -6.000000 % 1.3333333333 = -0.666667
- -5.000000 % 1.3333333333 = -1.000000
- -4.000000 % 1.3333333333 = 0.000000
- -3.000000 % 1.3333333333 = -0.333333
- -2.000000 % 1.3333333333 = -0.666667
- -1.000000 % 1.3333333333 = -1.000000
- 0.000000 % 1.3333333333 = 0.000000
- 1.000000 % 1.3333333333 = 1.000000
- 2.000000 % 1.3333333333 = 0.666667
- 3.000000 % 1.3333333333 = 0.333333
- 4.000000 % 1.3333333333 = 0.000000
- 5.000000 % 1.3333333333 = 1.000000
- 6.000000 % 1.3333333333 = 0.666667
- -4.500000 % 1.3333333333 = -0.500000
- 4.500000 % 1.3333333333 = 0.500000
- -1.333333 % 1.3333333333 = -1.333333
- 1.333333 % 1.3333333333 = 1.333333
- 0.500000 % 1.3333333333 = 0.500000
- -0.500000 % 1.3333333333 = -0.500000
- -201.000000 % 1.3333333333 = -1.000000
- 201.000000 % 1.3333333333 = 1.000000
-
- So it looks like it is fixed!
- --
- +--------------------------------+-------------------------------------------+
- | Drew Davidson | "When you're jacked up on 3 pots of |
- | Software Guy | coffee it's easy to make a mistake." |
- | First National Bank of Chicago | - Krantz and Stanely, |
- | drew@fnbc.com (NeXTmail) | "Programming the 68000" |
- +--------------------------------+-------------------------------------------+
-