Fix iabs and add some more tests
This commit is contained in:
parent
ee69cd7925
commit
29e01af6a6
@ -469,16 +469,25 @@ pub mod reimpls {
|
||||
}
|
||||
|
||||
trait AbsExt: Sized {
|
||||
fn uabs(self) -> u128_;
|
||||
fn iabs(self) -> i128_;
|
||||
}
|
||||
|
||||
impl AbsExt for i128_ {
|
||||
fn uabs(self) -> u128_ {
|
||||
self.iabs() as u128_
|
||||
}
|
||||
fn iabs(self) -> i128_;
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl AbsExt for i128_ {
|
||||
fn iabs(self) -> i128_ {
|
||||
((self ^ self).wrapping_sub(self))
|
||||
let s = self >> 63;
|
||||
((self ^ s).wrapping_sub(s))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl AbsExt for i128_ {
|
||||
fn iabs(self) -> i128_ {
|
||||
let s = self >> 127;
|
||||
((self ^ s).wrapping_sub(s))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,5 +91,9 @@ fn main() {
|
||||
format!("{:b}", j));
|
||||
assert_eq!("-147573952589676412928", format!("{:?}", j));
|
||||
// common traits
|
||||
x.clone();
|
||||
assert_eq!(x, b(x.clone()));
|
||||
// overflow checks
|
||||
assert_eq!((-z).checked_mul(-z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((k).checked_mul(k), None);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user