Fix int() method to return as-if this was a float

This commit is contained in:
Gwilym Kuiper 2021-06-05 17:23:28 +01:00
parent 8b1ad400a7
commit 56cf16def4

View file

@ -132,7 +132,14 @@ impl<const N: usize> Num<N> {
}
pub fn int(&self) -> i32 {
self.0 >> N
let fractional_part = self.0 & ((1 << N) - 1);
let self_as_int = self.0 >> N;
if self_as_int < 0 && fractional_part != 0 {
self_as_int + 1
} else {
self_as_int
}
}
pub fn new(integral: i32) -> Self {