From 5896501c2e8d7e297c94138b0dd7e5c799147f28 Mon Sep 17 00:00:00 2001 From: 0xPlish Date: Sun, 28 Apr 2024 17:31:52 -0700 Subject: [PATCH 1/3] Add a constant constructor --- src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 46aa0b2..0dab685 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -142,6 +142,14 @@ impl Fix { } } + /// Like `Self::new`, but creates numbers in the constant context. + pub const fn constant(bits: Bits) -> Self { + Fix { + bits, + marker: PhantomData, + } + } + /// Converts to another _Exp_. /// /// # Examples From a4c8619ad9fd34dc5f76b4097166bad8341459f4 Mon Sep 17 00:00:00 2001 From: 0xPlish Date: Sun, 28 Apr 2024 17:33:50 -0700 Subject: [PATCH 2/3] unit test for constant --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0dab685..0a2a0a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -853,4 +853,9 @@ mod tests { let end = Milli::new(u128::MAX); assert_eq!(start.abs_diff(&end), end); } + + #[test] + fn constant() { + assert_eq!(Kilo::constant(69u64), Kilo::new(69u64)); + } } From 662fe6a97156e4a3fe02438cd22455a18a4f5532 Mon Sep 17 00:00:00 2001 From: 0xPlish Date: Sun, 28 Apr 2024 17:35:26 -0700 Subject: [PATCH 3/3] Formatting --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0a2a0a7..f4383cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -856,6 +856,6 @@ mod tests { #[test] fn constant() { - assert_eq!(Kilo::constant(69u64), Kilo::new(69u64)); + assert_eq!(Kilo::constant(69u64), Kilo::new(69u64)); } }