mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +11:00
use easily optimisable division for truncate
This commit is contained in:
parent
eb212e7f91
commit
900b594039
|
@ -222,14 +222,7 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> Num<I, N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trunc(&self) -> I {
|
pub fn trunc(&self) -> I {
|
||||||
let fractional_part = self.0 & ((I::one() << N) - I::one());
|
self.0 / (I::one() << N)
|
||||||
let self_as_int = self.0 >> N;
|
|
||||||
|
|
||||||
if self_as_int < I::zero() && fractional_part != I::zero() {
|
|
||||||
self_as_int + I::one()
|
|
||||||
} else {
|
|
||||||
self_as_int
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rem_euclid(&self, rhs: Self) -> Self {
|
pub fn rem_euclid(&self, rhs: Self) -> Self {
|
||||||
|
|
Loading…
Reference in a new issue