mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Merge pull request #44 from corwinkuiper/num-from-to-raw
add from and to raw
This commit is contained in:
commit
1af22f56a3
|
@ -123,15 +123,23 @@ impl<const N: usize> Neg for Num<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> Num<N> {
|
impl<const N: usize> Num<N> {
|
||||||
pub fn max() -> Self {
|
pub const fn max() -> Self {
|
||||||
Num(i32::MAX)
|
Num(i32::MAX)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn min() -> Self {
|
pub const fn min() -> Self {
|
||||||
Num(i32::MIN)
|
Num(i32::MIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int(&self) -> i32 {
|
pub const fn from_raw(n: i32) -> Self {
|
||||||
|
Num(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn to_raw(&self) -> i32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn int(&self) -> i32 {
|
||||||
let fractional_part = self.0 & ((1 << N) - 1);
|
let fractional_part = self.0 & ((1 << N) - 1);
|
||||||
let self_as_int = self.0 >> N;
|
let self_as_int = self.0 >> N;
|
||||||
|
|
||||||
|
@ -155,7 +163,7 @@ impl<const N: usize> Num<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(integral: i32) -> Self {
|
pub const fn new(integral: i32) -> Self {
|
||||||
Self(integral << N)
|
Self(integral << N)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue