Skip to content

Instantly share code, notes, and snippets.

@dubzn
Created August 29, 2023 18:04
Show Gist options
  • Save dubzn/bb573c39c6810e55b35db8d1b5d4eb1d to your computer and use it in GitHub Desktop.
Save dubzn/bb573c39c6810e55b35db8d1b5d4eb1d to your computer and use it in GitHub Desktop.
// Test to evaluate rounding behavior and zeros
#[test]
fn test_division_round_with_negative_result() {
// -10/ 3 = 0
let a = IntegerTrait::<i256>::new(10, true);
let b = IntegerTrait::<i256>::new(3, false);
let (q, r) = a.div_rem(b);
assert(q.mag == 3 && r.mag == 1, '-10 / 3 = (-3, -1)'); // should be (-3, 1)?
assert(q.sign == true && r.sign == true, '(neg, neg)');
// -6 / 10 = -1 ?
let a = IntegerTrait::<i256>::new(6, true);
let b = IntegerTrait::<i256>::new(10, false);
let (q, r) = a.div_rem(b);
assert(q.mag == 1 && r.mag == 4, '-6 / 10 = (-1, 4)'); // should be (0, -4)?
// Following the previous behavior, the rest should be negative!
assert(q.sign == true && r.sign == true, '(neg, neg)'); // assert fails
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment