From 3b3e990c20d7db9071b7e255e81da8d24d3f6894 Mon Sep 17 00:00:00 2001 From: Jacek Generowicz Date: Fri, 23 Sep 2022 15:01:31 +0200 Subject: [PATCH] Move clamp into storage_type! block for Float only --- src/system.rs | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/system.rs b/src/system.rs index 977f8bb2..0fa9d35b 100644 --- a/src/system.rs +++ b/src/system.rs @@ -754,27 +754,43 @@ macro_rules! system { value: self.value.min(other.value), } } + } - /// f{32,64}: Restrict a value to a certain interval unless it is NaN. - /// Ord: Restrict a value to a certain interval. - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline(always)] - pub fn clamp(self, min: Self, max: Self) -> Self - where - V: $crate::num::Float, - { - Quantity { - dimension: $crate::lib::marker::PhantomData, - units: $crate::lib::marker::PhantomData, - value: self.value.clamp(min.value, max.value), + mod float { + storage_types! { + types: Float; + + use super::super::*; + + impl Quantity + where + D: Dimension + ?Sized, + U: Units + ?Sized, + { + + /// f{32,64}: Restrict a value to a certain interval unless it is NaN. + /// Ord: Restrict a value to a certain interval. + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline(always)] + pub fn clamp(self, min: Self, max: Self) -> Self + where + V: $crate::num::Float, + { + Quantity { + dimension: $crate::lib::marker::PhantomData, + units: $crate::lib::marker::PhantomData, + value: self.value.clamp(min.value, max.value), + } + } } } } + // Explicitly definte floating point methods for float and complex storage types. // `Complex` doesn't implement `Float`/`FloatCore`, but it does implement these methods // when the underlying type, `T`, implements `FloatCore`. - mod float { + mod float_and_complex { storage_types! { types: Float, Complex;