-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Integer modulo operation is not specified #493
Comments
Yes. the documentation has been lost over time... Added Area-Library, Triaged labels. |
This comment was originally written by [email protected] There appears to be a bug with large numbers in the Dart standalone VM when the first argument is negative: void main() { prints: 214114684949313328 The first result is expected since it satisfies 0 <= (a % b) <= abs(b). The second is a bug. |
This comment was originally written by [email protected] The Euclidean definition of mod is somewhat less useful without a corresponding Euclidean division operator. Together, the operators '/' and '%' should maintain the defining Euclidean properties: q = a / b To take a concrete example, let a = -8 and b = 3. Then the Euclidean modulus must be 1, since q * b + r == a and 1 is the only value for r in the range [0, 2] that makes (-8 - r) a multiple of 3. But then: q * 3 + 1 == -8 In other words, a Euclidean division operator must yield -8 / 3 == -3. However, Dart's integer division yields -8 ~/ 3 == -2 since it truncates (rounds to 0). So, while in some ways I appreciate the convenience of a '%' operator that always returns a non-negative result (e.g., due to its utility for accessing table entries using an expression like 'index % length'), it violates the natural expectation that (a / b) * b + (a % b) ==a. |
Updated the documentation with r20942. Added Fixed label. |
Changes: ``` > git log --format="%C(auto) %h %s" a70b93a..37951d1 https://dart.googlesource.com/markdown.git/+/37951d1 Fix an ImageSyntax issue (#493) https://dart.googlesource.com/markdown.git/+/29196b7 Refactor CodeBlockSyntax (#488) https://dart.googlesource.com/markdown.git/+/32c52d6 benchmark: use Stopwatch over DateTime for benchmarking (#491) https://dart.googlesource.com/markdown.git/+/0a7a531 Refactor ATX headings (#486) https://dart.googlesource.com/markdown.git/+/2fab846 some cleanup (#489) https://dart.googlesource.com/markdown.git/+/816dd87 Refactor CodeSyntax (#487) https://dart.googlesource.com/markdown.git/+/a529e58 Fix HTML escape issues (#484) ``` Diff: https://dart.googlesource.com/markdown.git/+/a70b93a1a004cc1da04a3e3ea59821ef8391e0d6~..37951d151750acfae756b2e466f563c1c5119b3d/ Change-Id: I3f8419477df2280801be3cf9251e003f6c482984 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270224 Commit-Queue: Samuel Rawlins <[email protected]> Auto-Submit: Devon Carew <[email protected]> Commit-Queue: Devon Carew <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
This issue was originally filed by [email protected]
Behavior of int.operator% is not specified.
Apparently it is not the same as ECMA-262 modulo
The text was updated successfully, but these errors were encountered: