From e55ef4d1522c1b49b45d192029bc257b4e5c2780 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sat, 5 Jun 2021 17:40:41 +0100 Subject: [PATCH 1/2] add from and to raw --- agb/src/number.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/agb/src/number.rs b/agb/src/number.rs index 632d5ee2..739b2276 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -131,6 +131,14 @@ impl Num { Num(i32::MIN) } + pub fn from_raw(n: i32) -> Self { + Num(n) + } + + pub fn to_raw(&self) -> i32 { + self.0 + } + pub fn int(&self) -> i32 { let fractional_part = self.0 & ((1 << N) - 1); let self_as_int = self.0 >> N; From 93b0b757bd13d2e0b88614e857b7900ac3a63a4d Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sat, 5 Jun 2021 17:53:07 +0100 Subject: [PATCH 2/2] make all const functions --- agb/src/number.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/agb/src/number.rs b/agb/src/number.rs index 739b2276..b6975b32 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -123,23 +123,23 @@ impl Neg for Num { } impl Num { - 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 from_raw(n: i32) -> Self { + pub const fn from_raw(n: i32) -> Self { Num(n) } - pub fn to_raw(&self) -> i32 { + pub const fn to_raw(&self) -> i32 { self.0 } - pub fn int(&self) -> i32 { + pub const fn int(&self) -> i32 { let fractional_part = self.0 & ((1 << N) - 1); let self_as_int = self.0 >> N; @@ -163,7 +163,7 @@ impl Num { } } - pub fn new(integral: i32) -> Self { + pub const fn new(integral: i32) -> Self { Self(integral << N) } }