Skip to content
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

v7.3.0: regression, modulo with negative number broken #1981

Closed
dnalborczyk opened this issue Sep 29, 2020 · 5 comments
Closed

v7.3.0: regression, modulo with negative number broken #1981

dnalborczyk opened this issue Sep 29, 2020 · 5 comments
Labels

Comments

@dnalborczyk
Copy link

repro:

v7.2.0

math.bignumber(-175).modulo(100)

// -75

v7.3.0

math.bignumber(-175).modulo(100)

// 25
@ovk
Copy link
Contributor

ovk commented Sep 29, 2020

Why you consider it broken? It was actually fixed in #1964 to behave as mathematical modulo operation (consistently with how it behaves for regular number type).

-175 mod 100 is indeed 25 as you can see here.

@dnalborczyk
Copy link
Author

interesting.

➜ node
Welcome to Node.js v14.12.0.
Type ".help" for more information.
> -175 % 100
-75
> 

@dnalborczyk
Copy link
Author

dnalborczyk commented Sep 30, 2020

nm, seems to be the difference between modulo and remainder: https://2ality.com/2019/08/remainder-vs-modulo.html, if that is the intend.

@josdejong
Copy link
Owner

nm, seems to be the difference between modulo and remainder: https://2ality.com/2019/08/remainder-vs-modulo.html, if that is the intend.

@dnalborczyk that is correct. In v7.3.0 we fixed/changed the behavior of modulus for BigNumbers to be consistent with how it's calculated for numbers in mathjs, and how it's calculated by the major math applications that I know of: as modulo operator like described in section "3 The modulo operator mod" of the article that you link to: https://2ality.com/2019/08/remainder-vs-modulo.html#the-modulo-operator-mod.

I hope this clarifies what's going on.

@dnalborczyk
Copy link
Author

thank you for the clarification! @josdejong @ovk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants