This commit is contained in:
varkor
2019-06-05 17:44:24 +01:00
parent e443e28da6
commit 98a45f4061
4 changed files with 23 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- minf
- min
- maxf
- max
## [v0.1.2] - 2018-07-18
+7
View File
@@ -426,6 +426,8 @@ pub trait F64Ext: private::Sealed + Sized {
fn atanh(self) -> Self;
fn min(self, other: Self) -> Self;
fn max(self, other: Self) -> Self;
}
impl F64Ext for f64 {
@@ -622,6 +624,11 @@ impl F64Ext for f64 {
fn min(self, other: Self) -> Self {
min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
max(self, other)
}
}
mod private {
+13
View File
@@ -0,0 +1,13 @@
#[inline]
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn max(x: f64, y: f64) -> f64 {
// 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
}
+2
View File
@@ -168,6 +168,7 @@ mod trunc;
mod truncf;
mod min;
mod minf;
mod max;
mod maxf;
// Use separated imports instead of {}-grouped imports for easier merging.
@@ -277,6 +278,7 @@ pub use self::trunc::trunc;
pub use self::truncf::truncf;
pub use self::min::min;
pub use self::minf::minf;
pub use self::max::max;
pub use self::maxf::maxf;
// Private modules