-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Use truncation division in mod for floats #7118
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
Conversation
|
Yes this changes an unnecessary inconsistency. Here is an example how it is now. import math
echo -3 mod 2
echo -3.0 mod 2.0output: But I am still agains this changes, I would prefer a lot if integers would behave like the float in this case and the result would be: I only need floor divison modulo. Never needed the truncating divison. Most of the time I use modulo is for indices of arrays |
|
Here's a good read on the different ways to implement I don't really have an opinion on floor div vs trunc div, but I doubt changing the behavior of div and mod for integers would be accepted since it will break a lot of code. |
|
C++ std::fmod
C++ std::remainder
Nim's output: import math
echo +5.1 mod +3.0
echo -5.1 mod +3.0
echo +5.1 mod -3.0
echo -5.1 mod -3.0
echo +0.0 mod 1.0
echo -0.0 mod 1.0
echo 5.1 mod Inf
echo +5.1 mod 0
|
fdb45df to
04dffae
Compare
|
I changed the PR to simply use use |
|
and this is what To be honest there are multiple definitions of |
|
I have changed my mind. I agree that this PR should be taken. @GULPF can you add an entry in the changelog.md? |
|
This needs a changelog entry. |
|
I like how it is now. When the tests are fixed. I would approve it. |
|
Ready to merge |
|
Changelog's entries for floorDiv/floorMod? |
This might just be a pointless breaking change, but it annoys me that modulus for floats uses floor division, when
divandmodfor integers uses truncating division.