#[inline] fn shr(self, rhs: $rhs) -> BigInt { let round_down = shr_round_down(&self, rhs); let data = self.data >> rhs; let data = if round_down { data + 1u8 } else { data };
BigInt::from_biguint(self.sign, data)
}
} impl Shr<$rhs> for &BigInt { type Output = BigInt;
#[inline] fn shr(self, rhs: $rhs) -> BigInt { let round_down = shr_round_down(self, rhs); let data = &self.data >> rhs; let data = if round_down { data + 1u8 } else { data };
BigInt::from_biguint(self.sign, data)
}
} impl ShrAssign<$rhs> for BigInt { #[inline] fn shr_assign(&mutself, rhs: $rhs) { let round_down = shr_round_down(self, rhs); self.data >>= rhs; if round_down { self.data += 1u8;
} elseifself.data.is_zero() { self.sign = NoSign;
}
}
}
impl_shift! { @ref Shr::shr, ShrAssign::shr_assign, $rhs }
)*};
}
// Negative values need a rounding adjustment if there are any ones in the // bits that are getting shifted out. fn shr_round_down<T: PrimInt>(i: &BigInt, shift: T) -> bool { if i.is_negative() { let zeros = i.trailing_zeros().expect("negative values are non-zero");
shift > T::zero() && shift.to_u64().map(|shift| zeros < shift).unwrap_or(true)
} else { false
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.