@@ -2,6 +2,15 @@ use compiler_builtins::int::{i256, u256, HInt, Int, MinInt};
2
2
3
3
const LOHI_SPLIT : u128 = 0xaaaaaaaaaaaaaaaaffffffffffffffff ;
4
4
5
+ /// Print a `u256` as hex since we can't add format implementations
6
+ fn hexu ( v : u256 ) -> String {
7
+ format ! ( "0x{:016x}{:016x}{:016x}{:016x}" , v. 0 [ 3 ] , v. 0 [ 2 ] , v. 0 [ 1 ] , v. 0 [ 0 ] )
8
+ }
9
+
10
+ fn hexi ( v : i256 ) -> String {
11
+ hexu ( v. unsigned ( ) )
12
+ }
13
+
5
14
#[ test]
6
15
fn widen_u128 ( ) {
7
16
assert_eq ! ( u128 :: MAX . widen( ) , u256( [ u64 :: MAX , u64 :: MAX , 0 , 0 ] ) ) ;
@@ -33,17 +42,17 @@ fn widen_mul_u128() {
33
42
] ;
34
43
35
44
let mut errors = Vec :: new ( ) ;
36
- for ( i, ( a, b, exp) ) in tests. iter ( ) . enumerate ( ) {
37
- let res = a. widen_mul ( * b) ;
38
- let res_z = a. zero_widen_mul ( * b) ;
45
+ for ( i, ( a, b, exp) ) in tests. iter ( ) . copied ( ) . enumerate ( ) {
46
+ let res = a. widen_mul ( b) ;
47
+ let res_z = a. zero_widen_mul ( b) ;
39
48
assert_eq ! ( res, res_z) ;
40
- if res != * exp {
49
+ if res != exp {
41
50
errors. push ( ( i, a, b, exp, res) ) ;
42
51
}
43
52
}
44
53
45
54
for ( i, a, b, exp, res) in & errors {
46
- eprintln ! ( "FAILURE ({i}): {a:#034x} * {b:#034x} = {exp:x } got {res:x}" ) ;
55
+ eprintln ! ( "FAILURE ({i}): {a:#034x} * {b:#034x} = {} got {}" , hexu ( * exp ) , hexu ( * res ) ) ;
47
56
}
48
57
assert ! ( errors. is_empty( ) ) ;
49
58
}
@@ -72,15 +81,16 @@ fn widen_mul_i128() {
72
81
] ;
73
82
74
83
let mut errors = Vec :: new ( ) ;
75
- for ( i, ( a, b, exp) ) in tests. iter ( ) . enumerate ( ) {
76
- let res = a. widen_mul ( * b) ;
77
- if res != * exp {
84
+ for ( i, ( a, b, exp) ) in tests. iter ( ) . copied ( ) . enumerate ( ) {
85
+ let res = a. widen_mul ( b) ;
86
+ // TODO check zero widen mul
87
+ if res != exp {
78
88
errors. push ( ( i, a, b, exp, res) ) ;
79
89
}
80
90
}
81
91
82
92
for ( i, a, b, exp, res) in & errors {
83
- eprintln ! ( "FAILURE ({i}): {a:#034x} * {b:#034x} = {exp:x } got {res:x}" ) ;
93
+ eprintln ! ( "FAILURE ({i}): {a:#034x} * {b:#034x} = {} got {}" , hexi ( * exp ) , hexi ( * res ) ) ;
84
94
}
85
95
assert ! ( errors. is_empty( ) ) ;
86
96
}
0 commit comments