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

Incorrect % (modulo) operator behavior for negative divisors #6609

Open
Aristotelis2002 opened this issue Nov 25, 2024 · 0 comments
Open

Incorrect % (modulo) operator behavior for negative divisors #6609

Aristotelis2002 opened this issue Nov 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Aristotelis2002
Copy link

Aristotelis2002 commented Nov 25, 2024

Aim

Attempted to create a simple program which does the modulo operation between a positive and a negative number.

The following main.nr:

fn main(x: i16, y: i16) {
    println(x % -13);
    println(x % y);
}

with Prover.toml:

x = "169"
y = "-13"

Outputs

169
169

This output is unexpected. It should be

0
0

Another example is the following main.nr:

fn main(x: i16, y: i16) {
    println(x % -107);
    println(x % y);
}

with Prover.toml:

x = "769"
y = "-107"

Outputs

769
769

In Rust the same program would have the output 20. In some other programming languages the output would be -20

Expected Behavior

Consisted behavior of the modulo operator. Currently the modulo operation between negative constants fails to compile but it has undefined behavior for negative integer parameters.

Bug

The modulo operator produces an incorrect value when working with negative values passed as parameters.

To Reproduce

  1. Create a Noir project with the provided code
  2. nargo check
  3. Insert the provided values into the Prover.toml
  4. nargo execute

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.39.0 noirc version = 0.39.0+45eb7568d56b2d254453b85f236d554232aa5df9 (git version hash: 45eb756, is dirty: false)

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@Aristotelis2002 Aristotelis2002 added the bug Something isn't working label Nov 25, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant