Add min
This commit is contained in:
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
### Added
|
||||
|
||||
- minf
|
||||
- min
|
||||
|
||||
## [v0.1.2] - 2018-07-18
|
||||
|
||||
|
||||
@@ -417,6 +417,8 @@ pub trait F64Ext: private::Sealed + Sized {
|
||||
fn acosh(self) -> Self;
|
||||
|
||||
fn atanh(self) -> Self;
|
||||
|
||||
fn min(self, other: Self) -> Self;
|
||||
}
|
||||
|
||||
impl F64Ext for f64 {
|
||||
@@ -608,6 +610,11 @@ impl F64Ext for f64 {
|
||||
fn atanh(self) -> Self {
|
||||
atanh(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn min(self, other: Self) -> Self {
|
||||
min(self, other)
|
||||
}
|
||||
}
|
||||
|
||||
mod private {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#[inline]
|
||||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
||||
pub fn min(x: f64, y: f64) -> f64 {
|
||||
// IEEE754 says: minNum(x, y) is the canonicalized number x if x < y, y 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 y.is_nan() || x < y { x } else { y }) * 1.0
|
||||
}
|
||||
@@ -166,6 +166,7 @@ mod tgamma;
|
||||
mod tgammaf;
|
||||
mod trunc;
|
||||
mod truncf;
|
||||
mod min;
|
||||
mod minf;
|
||||
|
||||
// Use separated imports instead of {}-grouped imports for easier merging.
|
||||
@@ -273,6 +274,7 @@ pub use self::tgamma::tgamma;
|
||||
pub use self::tgammaf::tgammaf;
|
||||
pub use self::trunc::trunc;
|
||||
pub use self::truncf::truncf;
|
||||
pub use self::min::min;
|
||||
pub use self::minf::minf;
|
||||
|
||||
// Private modules
|
||||
|
||||
Reference in New Issue
Block a user