Wrong results with Excel MOD function?
I have three MOD calculations, Excel 2003 and 2013 bring up these results:
MOD(-7000;-12) = -4
MOD(7000;-12) = -8
MOD(-7000;12) = 8
Whereas in windows calculator, my own math and c# all bring up: -4,4, and -4 respectively for the above formulas. (First one is correct for both).
I calculate those by doing the following: double x = 7000 % -12;
Are these results correct for excel or not? If not, then my guess is the internal formula for these would start something like this:
7000 / -12 = -583.333
INT(-583.333) = -584 --- NOT -583, and this is where the error occurs.
So my guess is this error occurs, and only occurs, when dividing the dividend by the divisor that results in a negative number.
But such a simple error in such a popular application for such a long time, I couldn't imagine it. So what am I doing wrong?
Edit: I just looked up the function a little better. Among the things microsoft says is: "the result has the same sign as divisor." What do they mean by this and does that explain anything with my results?
http://office.microsoft.com/en-us/excel-help/mod-HP005209182.aspx
Okay it's clear that they want the results as they are. Look at the examples at the bottom of the given link. So my question is why the difference in implementation?
I have three MOD calculations, Excel 2003 and 2013 bring up these results:
MOD(-7000;-12) = -4
MOD(7000;-12) = -8
MOD(-7000;12) = 8
Whereas in windows calculator, my own math and c# all bring up: -4,4, and -4 respectively for the above formulas. (First one is correct for both).
I calculate those by doing the following: double x = 7000 % -12;
Are these results correct for excel or not? If not, then my guess is the internal formula for these would start something like this:
7000 / -12 = -583.333
INT(-583.333) = -584 --- NOT -583, and this is where the error occurs.
So my guess is this error occurs, and only occurs, when dividing the dividend by the divisor that results in a negative number.
But such a simple error in such a popular application for such a long time, I couldn't imagine it. So what am I doing wrong?
Edit: I just looked up the function a little better. Among the things microsoft says is: "the result has the same sign as divisor." What do they mean by this and does that explain anything with my results?
http://office.microsoft.com/en-us/excel-help/mod-HP005209182.aspx
Okay it's clear that they want the results as they are. Look at the examples at the bottom of the given link. So my question is why the difference in implementation?
No comments:
Post a Comment