rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
731 stars 135 forks source link

Feature Request: Add "Maximum" and "Minimum" traits (or a combined `MiniMax` trait) #93

Closed phayes closed 6 years ago

phayes commented 6 years ago

Often times, it is useful to know the maximum and minimum values allowed by a numeric type.

I'm hoping we could see a fairly simple trait that looks someting like this:

pub trait MiniMax {
    fn maximum() -> Self;
    fn minimum() -> Self;
}

Some examples:

  1. u32.maximum() would return std::u32::MAX
  2. u32.minimum() would return 0
  3. f64.maximum() would return std::f64::INFINITY
  4. f64.minimum() would return std::f64::NEG_INFINITY

Unbounded finite types like BigInt simply wouldn't implement this trait.

cuviper commented 6 years ago

That would be Bounded, although for floats it returns the min/max finite values.

phayes commented 6 years ago

Silly me, there it is. Apologies for the noise on the issue queue. Closing this.