Skip to content

Commit

Permalink
Move clamp into storage_type! block for Float only
Browse files Browse the repository at this point in the history
  • Loading branch information
jacg committed Sep 23, 2022
1 parent f90e8bc commit 3b3e990
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D, U> Quantity<D, U, V>
where
D: Dimension + ?Sized,
U: Units<V> + ?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<T>` 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;

Expand Down

0 comments on commit 3b3e990

Please sign in to comment.