-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modulus calculation is not correct. #16
Comments
I try to provide the same result as Dart VM. main() {
print(5 % 4); // 1
print((-5) % 4); // 3
print(5 % (-4)); // 1
print((-5) % (-4)); // 3
print(4 % 4); // 0
print((-4) % 4); // 0
print(4 % (-4)); // 0
print((-4) % (-4)); // 0
print(new Rational(5) % new Rational(4)); // 1
print(new Rational(-5) % new Rational(4)); // 3
print(new Rational(5) % new Rational(-4)); // 1
print(new Rational(-5) % new Rational(-4)); // 3
print(new Rational(4) % new Rational(4)); // 0
print(new Rational(-4) % new Rational(4)); // 4 - incorrect
print(new Rational(4) % new Rational(-4)); // 0
print(new Rational(-4) % new Rational(-4)); // 4 - incorrect
} There are indeed 2 incorrect results but not those you mentioned. |
Also some tests in rational package were wrong.
|
Not all the cases in my original post were wrong. |
Effectively, the VM results are wrong (at least when the result should be negative) ... , they are different also from Javascript (also these are wrong :-( ). |
As I said above
On the VM: print(5 % (-4)); // 1
print((-5) % (-4)); // 3 So I can not change these results unless the VM results are changed. |
Might be related to dart-lang/sdk#28408 (comment) |
See also dart-lang/sdk#493 |
Based on wikipedia, both the calculation I proposed and the VM one are correct. |
Fixed in version 0.1.10. |
humm, still an issue in browser... :-/ |
fix in browser too in 0.1.10+1 |
There is a problem with modulus calculation when the dividend and/or the divisor are negative numbers.
I attach a simple test file with a new method
mod
that could be a possible solution (useful to understand the logic) and a more compact one (mod2
).The text was updated successfully, but these errors were encountered: