File tree 2 files changed +18
-5
lines changed
2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -469,16 +469,25 @@ pub mod reimpls {
469
469
}
470
470
471
471
trait AbsExt : Sized {
472
- fn uabs ( self ) -> u128_ ;
472
+ fn uabs ( self ) -> u128_ {
473
+ self . iabs ( ) as u128_
474
+ }
473
475
fn iabs ( self ) -> i128_ ;
474
476
}
475
477
478
+ #[ cfg( stage0) ]
476
479
impl AbsExt for i128_ {
477
- fn uabs ( self ) -> u128_ {
478
- self . iabs ( ) as u128_
480
+ fn iabs ( self ) -> i128_ {
481
+ let s = self >> 63 ;
482
+ ( ( self ^ s) . wrapping_sub ( s) )
479
483
}
484
+ }
485
+
486
+ #[ cfg( not( stage0) ) ]
487
+ impl AbsExt for i128_ {
480
488
fn iabs ( self ) -> i128_ {
481
- ( ( self ^ self ) . wrapping_sub ( self ) )
489
+ let s = self >> 127 ;
490
+ ( ( self ^ s) . wrapping_sub ( s) )
482
491
}
483
492
}
484
493
Original file line number Diff line number Diff line change @@ -91,5 +91,9 @@ fn main() {
91
91
format!( "{:b}" , j) ) ;
92
92
assert_eq ! ( "-147573952589676412928" , format!( "{:?}" , j) ) ;
93
93
// common traits
94
- x. clone ( ) ;
94
+ assert_eq ! ( x, b( x. clone( ) ) ) ;
95
+ // overflow checks
96
+ assert_eq ! ( ( -z) . checked_mul( -z) , Some ( 0x734C_C2F2_A521 ) ) ;
97
+ assert_eq ! ( ( z) . checked_mul( z) , Some ( 0x734C_C2F2_A521 ) ) ;
98
+ assert_eq ! ( ( k) . checked_mul( k) , None ) ;
95
99
}
You can’t perform that action at this time.
0 commit comments