Add maxf
This commit is contained in:
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
- minf
|
||||
- min
|
||||
- maxf
|
||||
|
||||
## [v0.1.2] - 2018-07-18
|
||||
|
||||
|
||||
@@ -138,6 +138,8 @@ pub trait F32Ext: private::Sealed + Sized {
|
||||
fn atanh(self) -> Self;
|
||||
|
||||
fn min(self, other: Self) -> Self;
|
||||
|
||||
fn max(self, other: Self) -> Self;
|
||||
}
|
||||
|
||||
impl F32Ext for f32 {
|
||||
@@ -334,6 +336,11 @@ impl F32Ext for f32 {
|
||||
fn min(self, other: Self) -> Self {
|
||||
minf(self, other)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn max(self, other: Self) -> Self {
|
||||
maxf(self, other)
|
||||
}
|
||||
}
|
||||
|
||||
/// Math support for `f64`
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#[inline]
|
||||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
||||
pub fn maxf(x: f32, y: f32) -> f32 {
|
||||
// IEEE754 says: maxNum(x, y) is the canonicalized number y if x < y, x if y < x, the
|
||||
// canonicalized number if one operand is a number and the other a quiet NaN. Otherwise it
|
||||
// is either x or y, canonicalized (this means results might differ among implementations).
|
||||
// When either x or y is a signalingNaN, then the result is according to 6.2.
|
||||
//
|
||||
// Since we do not support sNaN in Rust yet, we do not need to handle them.
|
||||
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
|
||||
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
|
||||
(if x.is_nan() || x < y { y } else { x }) * 1.0
|
||||
}
|
||||
@@ -168,6 +168,7 @@ mod trunc;
|
||||
mod truncf;
|
||||
mod min;
|
||||
mod minf;
|
||||
mod maxf;
|
||||
|
||||
// Use separated imports instead of {}-grouped imports for easier merging.
|
||||
pub use self::acos::acos;
|
||||
@@ -276,6 +277,7 @@ pub use self::trunc::trunc;
|
||||
pub use self::truncf::truncf;
|
||||
pub use self::min::min;
|
||||
pub use self::minf::minf;
|
||||
pub use self::maxf::maxf;
|
||||
|
||||
// Private modules
|
||||
mod expo2;
|
||||
|
||||
Reference in New Issue
Block a user