-
Notifications
You must be signed in to change notification settings - Fork 323
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
Make the%
consistent across both Integer
sizes.
#9589
Conversation
@@ -515,6 +515,11 @@ type Float | |||
Modulus in Enso will undergo automatic conversions such that you need | |||
not convert between Integer and Float manually. | |||
|
|||
? Negative Arguments | |||
|
|||
When the first argument to `%` is negative, the result will also be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
@@ -349,8 +349,7 @@ add_specs suite_builder = | |||
hundred_factorial%hundred_factorial . should_equal 0 | |||
10%hundred_factorial . should_equal 10 | |||
|
|||
# Pending https://github.com/enso-org/enso/issues/9553 | |||
group_builder.specify "should define modulo for negative integers and decimals" pending="large integer % is incorrect" <| | |||
group_builder.specify "should define modulo for negative integers and decimals" <| | |||
-5%3 . should_equal -2 | |||
-5%3 . should_be_a Integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to add more examples like those mentioned in the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misunderstood you and added Examples to the documentation. Now I have added the example cases from the PR description.
There is no clear consensus about what
%
should mean when the first operand is negative.The current behavior is that negative
Integer
values that fit in aLong
return a negative result, while largerInteger
values return a positive result:Gives
For consistency, we'll return negative values for all
Integer
values. This makes it consistent with both Java, C, and C++%
.(This is sometimes called
remainder
rather thanmodulo
, but since programmers usually call this operatormodulo
we'll keep the original name of the method inside BigIntegerOps.)Closes #9553.
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
./run ide build
.