File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -469,16 +469,25 @@ pub mod reimpls {
469469 }
470470
471471 trait AbsExt : Sized {
472- fn uabs ( self ) -> u128_ ;
472+ fn uabs ( self ) -> u128_ {
473+ self . iabs ( ) as u128_
474+ }
473475 fn iabs ( self ) -> i128_ ;
474476 }
475477
478+ #[ cfg( stage0) ]
476479 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) )
479483 }
484+ }
485+
486+ #[ cfg( not( stage0) ) ]
487+ impl AbsExt for i128_ {
480488 fn iabs ( self ) -> i128_ {
481- ( ( self ^ self ) . wrapping_sub ( self ) )
489+ let s = self >> 127 ;
490+ ( ( self ^ s) . wrapping_sub ( s) )
482491 }
483492 }
484493
Original file line number Diff line number Diff line change @@ -91,5 +91,9 @@ fn main() {
9191 format!( "{:b}" , j) ) ;
9292 assert_eq ! ( "-147573952589676412928" , format!( "{:?}" , j) ) ;
9393 // 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 ) ;
9599}
You can’t perform that action at this time.
0 commit comments