Skip to content

Commit 53203b0

Browse files
committed
Update big tests
1 parent c18d396 commit 53203b0

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/int/big.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ impl MinInt for i256 {
6262
const SIGNED: bool = false;
6363
const BITS: u32 = 256;
6464
const ZERO: Self = Self([0u64; 4]);
65-
const ONE: Self = Self([0, 0, 0, 1]);
66-
const MIN: Self = Self([0u64; 4]);
67-
const MAX: Self = Self([u64::MAX; 4]);
65+
const ONE: Self = Self([1, 0, 0, 0]);
66+
const MIN: Self = Self([0, 0, 0, 1 << 63]);
67+
const MAX: Self = Self([u64::MAX, u64::MAX, u64::MAX, u64::MAX << 1]);
6868
}
6969

7070
// impl Int for i256 {

testcrate/tests/big.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use compiler_builtins::int::{i256, u256, HInt, MinInt};
1+
use compiler_builtins::int::{i256, u256, HInt, Int, MinInt};
22

33
const LOHI_SPLIT: u128 = 0xaaaaaaaaaaaaaaaaffffffffffffffff;
44

@@ -34,7 +34,9 @@ fn widen_mul_u128() {
3434

3535
let mut errors = Vec::new();
3636
for (i, (a, b, exp)) in tests.iter().enumerate() {
37-
let res = a.zero_widen_mul(*b);
37+
let res = a.widen_mul(*b);
38+
let res_z = a.zero_widen_mul(*b);
39+
assert_eq!(res, res_z);
3840
if res != *exp {
3941
errors.push((i, a, b, exp, res));
4042
}
@@ -52,13 +54,17 @@ fn widen_mul_i128() {
5254
(
5355
i128::MAX / 2,
5456
2_i128,
55-
i256([u64::MAX, u64::MAX, u64::MAX, u64::MAX]),
57+
i256([u64::MAX - 1, u64::MAX >> 1, 0, 0]),
5658
),
57-
(i128::MAX, 2_i128, i256([u64::MAX - 1, u64::MAX, 1, 0])),
58-
(i128::MIN, 2_i128, i256([u64::MAX - 1, u64::MAX, 1, 0])),
59-
(i128::MAX, i128::MAX, i256([1, 0, u64::MAX - 1, u64::MAX])),
60-
(i128::MAX, i128::MAX, i256([1, 0, u64::MAX - 1, u64::MAX])),
61-
(i128::MIN, i128::MIN, i256::ZERO),
59+
(i128::MAX, 2_i128, i256([u64::MAX - 1, u64::MAX, 0, 0])),
60+
(i128::MIN, 2_i128, i256([0, 0, u64::MAX, u64::MAX])),
61+
(
62+
i128::MAX,
63+
i128::MAX,
64+
i256([1, 0, u64::MAX - 1, u64::MAX >> 2]),
65+
),
66+
(i128::MAX, i128::MIN, i256([0, 0, 0, 0b11 << 62])),
67+
(i128::MIN, i128::MIN, i256([0, 0, 0, 0])),
6268
(1234, 0, i256::ZERO),
6369
(0, 1234, i256::ZERO),
6470
(-1234, 0, i256::ZERO),
@@ -67,7 +73,7 @@ fn widen_mul_i128() {
6773

6874
let mut errors = Vec::new();
6975
for (i, (a, b, exp)) in tests.iter().enumerate() {
70-
let res = a.zero_widen_mul(*b);
76+
let res = a.widen_mul(*b);
7177
if res != *exp {
7278
errors.push((i, a, b, exp, res));
7379
}

0 commit comments

Comments
 (0)