Merge pull request #44 from corwinkuiper/num-from-to-raw

add from and to raw
This commit is contained in:
Corwin 2021-06-05 18:02:15 +01:00 committed by GitHub
commit 1af22f56a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -123,15 +123,23 @@ impl<const N: usize> Neg for Num<N> {
}
impl<const N: usize> Num<N> {
pub fn max() -> Self {
pub const fn max() -> Self {
Num(i32::MAX)
}
pub fn min() -> Self {
pub const fn min() -> Self {
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 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)
}
}