Skip to main content

Min

Trait Min 

Source
pub trait Min: PartialOrd + Sized {
    // Provided methods
    fn min_by_ref<'a>(&'a self, other: &'a Self) -> &'a Self { ... }
    fn min_by_value(self, other: Self) -> Self { ... }
}
Expand description

A trait for finding the minimum of two values.

This trait provides a min method that returns a reference to the lesser of two values. It is bounded by PartialOrd.

§Implementations

  • For types that already guarantee validity, like RealValidated, the default implementation is sufficient and safe.
  • A specialized implementation is provided for f64 to add validation checks in debug builds.

§Behavior with NaN

For f64, if either input is NaN, the comparison self <= other is false, which means other will be returned. Note that in debug builds, providing a NaN input will cause a panic. RealValidated types should not contain NaN values by contract.

Provided Methods§

Source

fn min_by_ref<'a>(&'a self, other: &'a Self) -> &'a Self

Returns a reference to the minimum of self and other.

§Examples
use num_valid::functions::Min;

assert_eq!(Min::min_by_ref(&5.0, &3.0), &3.0);
assert_eq!(Min::min_by_ref(&-10.0, &-5.0), &-10.0);
Source

fn min_by_value(self, other: Self) -> Self

Returns the minimum of self and other, consuming both values.

§Examples
use num_valid::functions::Min;

assert_eq!(5.0f64.min_by_value(3.0), 3.0);
assert_eq!((-10.0f64).min_by_value(-5.0), -10.0);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<K: NumKernel> Min for RealValidated<K>

Source§

impl<RealType: RealScalar> Min for NonNegativeRealScalar<RealType>

Implements Min for NonNegativeRealScalar.

Minimum selection is delegated to the default trait behavior based on PartialOrd.

Source§

impl<RealType: RealScalar> Min for PositiveRealScalar<RealType>

Implements Min for PositiveRealScalar.

Minimum selection is delegated to the default trait behavior based on PartialOrd.

Source§

impl<T: NativeReal> Min for T

Specialized implementation of Max and Min for `f64