Skip to content

Commit

Permalink
Update big tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Apr 16, 2024
1 parent a380257 commit a19f4ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/int/big.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ impl MinInt for i256 {
const SIGNED: bool = false;
const BITS: u32 = 256;
const ZERO: Self = Self([0u64; 4]);
const ONE: Self = Self([0, 0, 0, 1]);
const MIN: Self = Self([0u64; 4]);
const MAX: Self = Self([u64::MAX; 4]);
const ONE: Self = Self([1, 0, 0, 0]);
const MIN: Self = Self([0, 0, 0, 1 << 63]);
const MAX: Self = Self([u64::MAX, u64::MAX, u64::MAX, u64::MAX << 1]);
}

// impl Int for i256 {
Expand Down
24 changes: 15 additions & 9 deletions testcrate/tests/big.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use compiler_builtins::int::{i256, u256, HInt, MinInt};
use compiler_builtins::int::{i256, u256, HInt, Int, MinInt};

const LOHI_SPLIT: u128 = 0xaaaaaaaaaaaaaaaaffffffffffffffff;

Expand Down Expand Up @@ -34,7 +34,9 @@ fn widen_mul_u128() {

let mut errors = Vec::new();
for (i, (a, b, exp)) in tests.iter().enumerate() {
let res = a.zero_widen_mul(*b);
let res = a.widen_mul(*b);
let res_z = a.zero_widen_mul(*b);
assert_eq!(res, res_z);
if res != *exp {
errors.push((i, a, b, exp, res));
}
Expand All @@ -52,13 +54,17 @@ fn widen_mul_i128() {
(
i128::MAX / 2,
2_i128,
i256([u64::MAX, u64::MAX, u64::MAX, u64::MAX]),
i256([u64::MAX - 1, u64::MAX >> 1, 0, 0]),
),
(i128::MAX, 2_i128, i256([u64::MAX - 1, u64::MAX, 1, 0])),
(i128::MIN, 2_i128, i256([u64::MAX - 1, u64::MAX, 1, 0])),
(i128::MAX, i128::MAX, i256([1, 0, u64::MAX - 1, u64::MAX])),
(i128::MAX, i128::MAX, i256([1, 0, u64::MAX - 1, u64::MAX])),
(i128::MIN, i128::MIN, i256::ZERO),
(i128::MAX, 2_i128, i256([u64::MAX - 1, u64::MAX, 0, 0])),
(i128::MIN, 2_i128, i256([0, 0, u64::MAX, u64::MAX])),
(
i128::MAX,
i128::MAX,
i256([1, 0, u64::MAX - 1, u64::MAX >> 2]),
),
(i128::MAX, i128::MIN, i256([0, 0, 0, 0b11 << 62])),
(i128::MIN, i128::MIN, i256([0, 0, 0, 0])),
(1234, 0, i256::ZERO),
(0, 1234, i256::ZERO),
(-1234, 0, i256::ZERO),
Expand All @@ -67,7 +73,7 @@ fn widen_mul_i128() {

let mut errors = Vec::new();
for (i, (a, b, exp)) in tests.iter().enumerate() {
let res = a.zero_widen_mul(*b);
let res = a.widen_mul(*b);
if res != *exp {
errors.push((i, a, b, exp, res));
}
Expand Down

0 comments on commit a19f4ec

Please sign in to comment.