@@ -193,14 +193,45 @@ fn main() {
193
193
assert_eq!(r.saturating_pow(3), -8 as i128);
194
194
assert_eq!(r.saturating_pow(0), 1 as i128);*/
195
195
196
- use std:: i128:: { MAX , MIN } ;
197
- assert_eq ! ( ( 0 as i128 ) . saturating_neg( ) , 0 ) ;
198
- assert_eq ! ( ( 123 as i128 ) . saturating_neg( ) , -123 ) ;
199
- assert_eq ! ( ( -123 as i128 ) . saturating_neg( ) , 123 ) ;
200
- assert_eq ! ( ( MAX - 2 ) . saturating_neg( ) , MIN + 3 ) ;
201
- assert_eq ! ( ( MAX - 1 ) . saturating_neg( ) , MIN + 2 ) ;
202
- assert_eq ! ( MAX . saturating_neg( ) , MIN + 1 ) ;
203
- assert_eq ! ( ( MIN + 2 ) . saturating_neg( ) , MAX - 1 ) ;
204
- assert_eq ! ( ( MIN + 1 ) . saturating_neg( ) , MAX ) ;
205
- assert_eq ! ( MIN . saturating_neg( ) , MAX ) ;
196
+ const A : u64 = 0b0101100 ;
197
+ const B : u64 = 0b0100001 ;
198
+ const C : u64 = 0b1111001 ;
199
+
200
+ const _0: u64 = 0 ;
201
+ const _1: u64 = !0 ;
202
+
203
+ assert_eq ! ( A . reverse_bits( ) . reverse_bits( ) , A ) ;
204
+ assert_eq ! ( B . reverse_bits( ) . reverse_bits( ) , B ) ;
205
+ assert_eq ! ( C . reverse_bits( ) . reverse_bits( ) , C ) ;
206
+
207
+ // Swapping these should make no difference
208
+ assert_eq ! ( _0. reverse_bits( ) , _0) ;
209
+ assert_eq ! ( _1. reverse_bits( ) , _1) ;
210
+
211
+ /*const _0: i128 = 0;
212
+ const _1: i128 = !0;
213
+
214
+ use std::i128::MAX;
215
+
216
+ let a: i128 = 0b0101_1111;
217
+ assert_eq!(a.trailing_ones(), 5);
218
+ assert_eq!((!a).leading_ones(), i128::BITS - 7);
219
+
220
+ assert_eq!(a.reverse_bits().leading_ones(), 5);
221
+
222
+ assert_eq!(_1.leading_ones(), i128::BITS);
223
+ assert_eq!(_1.trailing_ones(), i128::BITS);
224
+
225
+ assert_eq!((_1 << 1).trailing_ones(), 0);
226
+ assert_eq!(MAX.leading_ones(), 0);
227
+
228
+ assert_eq!((_1 << 1).leading_ones(), i128::BITS - 1);
229
+ assert_eq!(MAX.trailing_ones(), i128::BITS - 1);
230
+
231
+ assert_eq!(_0.leading_ones(), 0);
232
+ assert_eq!(_0.trailing_ones(), 0);
233
+
234
+ let x: i128 = 0b0010_1100;
235
+ assert_eq!(x.leading_ones(), 0);
236
+ assert_eq!(x.trailing_ones(), 0);*/
206
237
}
0 commit comments