From 0e9c6061551c0d6d869aac1dbaaacac3e89d7884 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 5 Jun 2019 17:43:46 +0100 Subject: [PATCH 1/6] Add minf --- CHANGELOG.md | 4 ++++ src/lib.rs | 7 +++++++ src/math/minf.rs | 13 +++++++++++++ src/math/mod.rs | 2 ++ 4 files changed, 26 insertions(+) create mode 100644 src/math/minf.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cc396455..f8d4e98f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- minf + ## [v0.1.2] - 2018-07-18 ### Added diff --git a/src/lib.rs b/src/lib.rs index 0d0f6155a..763920cc5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,6 +136,8 @@ pub trait F32Ext: private::Sealed + Sized { fn acosh(self) -> Self; fn atanh(self) -> Self; + + fn min(self, other: Self) -> Self; } impl F32Ext for f32 { @@ -327,6 +329,11 @@ impl F32Ext for f32 { fn atanh(self) -> Self { atanhf(self) } + + #[inline] + fn min(self, other: Self) -> Self { + minf(self, other) + } } /// Math support for `f64` diff --git a/src/math/minf.rs b/src/math/minf.rs new file mode 100644 index 000000000..2098a2d75 --- /dev/null +++ b/src/math/minf.rs @@ -0,0 +1,13 @@ +#[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn minf(x: f32, y: f32) -> f32 { + // 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 +} diff --git a/src/math/mod.rs b/src/math/mod.rs index c4d247414..90c5fd311 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -166,6 +166,7 @@ mod tgamma; mod tgammaf; mod trunc; mod truncf; +mod minf; // Use separated imports instead of {}-grouped imports for easier merging. pub use self::acos::acos; @@ -272,6 +273,7 @@ pub use self::tgamma::tgamma; pub use self::tgammaf::tgammaf; pub use self::trunc::trunc; pub use self::truncf::truncf; +pub use self::minf::minf; // Private modules mod expo2; From 563a4703e139177e46133ba739cee8c3c280e864 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 5 Jun 2019 17:44:06 +0100 Subject: [PATCH 2/6] Add min --- CHANGELOG.md | 1 + src/lib.rs | 7 +++++++ src/math/min.rs | 13 +++++++++++++ src/math/mod.rs | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 src/math/min.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d4e98f0..4ecd8c8ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - minf +- min ## [v0.1.2] - 2018-07-18 diff --git a/src/lib.rs b/src/lib.rs index 763920cc5..b72b58c1f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { diff --git a/src/math/min.rs b/src/math/min.rs new file mode 100644 index 000000000..d0345cf8d --- /dev/null +++ b/src/math/min.rs @@ -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 +} diff --git a/src/math/mod.rs b/src/math/mod.rs index 90c5fd311..e2d706201 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -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 From e443e28da63eeed1db77ec2d13584f2cbaed69a5 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 5 Jun 2019 17:44:20 +0100 Subject: [PATCH 3/6] Add maxf --- CHANGELOG.md | 1 + src/lib.rs | 7 +++++++ src/math/maxf.rs | 13 +++++++++++++ src/math/mod.rs | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 src/math/maxf.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ecd8c8ab..7fb17cc9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - minf - min +- maxf ## [v0.1.2] - 2018-07-18 diff --git a/src/lib.rs b/src/lib.rs index b72b58c1f..368e25c8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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` diff --git a/src/math/maxf.rs b/src/math/maxf.rs new file mode 100644 index 000000000..ac0d22aa5 --- /dev/null +++ b/src/math/maxf.rs @@ -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 +} diff --git a/src/math/mod.rs b/src/math/mod.rs index e2d706201..9feadce7d 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -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; From 98a45f4061b433bb6d0825d463e29b48371ab22a Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 5 Jun 2019 17:44:24 +0100 Subject: [PATCH 4/6] Add max --- CHANGELOG.md | 1 + src/lib.rs | 7 +++++++ src/math/max.rs | 13 +++++++++++++ src/math/mod.rs | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 src/math/max.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb17cc9f..d7667c0a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - minf - min - maxf +- max ## [v0.1.2] - 2018-07-18 diff --git a/src/lib.rs b/src/lib.rs index 368e25c8c..f77cda94b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { diff --git a/src/math/max.rs b/src/math/max.rs new file mode 100644 index 000000000..3fbb48024 --- /dev/null +++ b/src/math/max.rs @@ -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 +} diff --git a/src/math/mod.rs b/src/math/mod.rs index 9feadce7d..c2bc9a475 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -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 From a76215965b6d2873916c86f63dfba57315af92d9 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 5 Jun 2019 20:59:05 +0100 Subject: [PATCH 5/6] Alphabetise --- src/math/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/math/mod.rs b/src/math/mod.rs index c2bc9a475..bedc3a69e 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -140,6 +140,10 @@ mod log1pf; mod log2; mod log2f; mod logf; +mod max; +mod maxf; +mod min; +mod minf; mod modf; mod modff; mod pow; @@ -166,10 +170,6 @@ mod tgamma; mod tgammaf; mod trunc; mod truncf; -mod min; -mod minf; -mod max; -mod maxf; // Use separated imports instead of {}-grouped imports for easier merging. pub use self::acos::acos; @@ -250,6 +250,10 @@ pub use self::log1pf::log1pf; pub use self::log2::log2; pub use self::log2f::log2f; pub use self::logf::logf; +pub use self::max::max; +pub use self::maxf::maxf; +pub use self::min::min; +pub use self::minf::minf; pub use self::modf::modf; pub use self::modff::modff; pub use self::pow::pow; @@ -276,10 +280,6 @@ 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; -pub use self::max::max; -pub use self::maxf::maxf; // Private modules mod expo2; From 03b46a940d21ed51c07b8e24063b30c534fcaf79 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 5 Jun 2019 21:13:25 +0100 Subject: [PATCH 6/6] Correct libm names --- CHANGELOG.md | 6 +++--- src/lib.rs | 8 ++++---- src/math/{max.rs => fmax.rs} | 2 +- src/math/{maxf.rs => fmaxf.rs} | 2 +- src/math/{min.rs => fmin.rs} | 2 +- src/math/{minf.rs => fminf.rs} | 2 +- src/math/mod.rs | 16 ++++++++-------- 7 files changed, 19 insertions(+), 19 deletions(-) rename src/math/{max.rs => fmax.rs} (95%) rename src/math/{maxf.rs => fmaxf.rs} (95%) rename src/math/{min.rs => fmin.rs} (95%) rename src/math/{minf.rs => fminf.rs} (95%) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7667c0a1..62bfd0d5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - minf -- min -- maxf -- max +- fmin +- fmaxf +- fmax ## [v0.1.2] - 2018-07-18 diff --git a/src/lib.rs b/src/lib.rs index f77cda94b..df3c8cf60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -334,12 +334,12 @@ impl F32Ext for f32 { #[inline] fn min(self, other: Self) -> Self { - minf(self, other) + fminf(self, other) } #[inline] fn max(self, other: Self) -> Self { - maxf(self, other) + fmaxf(self, other) } } @@ -622,12 +622,12 @@ impl F64Ext for f64 { #[inline] fn min(self, other: Self) -> Self { - min(self, other) + fmin(self, other) } #[inline] fn max(self, other: Self) -> Self { - max(self, other) + fmax(self, other) } } diff --git a/src/math/max.rs b/src/math/fmax.rs similarity index 95% rename from src/math/max.rs rename to src/math/fmax.rs index 3fbb48024..22016d11c 100644 --- a/src/math/max.rs +++ b/src/math/fmax.rs @@ -1,6 +1,6 @@ #[inline] #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn max(x: f64, y: f64) -> f64 { +pub fn fmax(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). diff --git a/src/math/maxf.rs b/src/math/fmaxf.rs similarity index 95% rename from src/math/maxf.rs rename to src/math/fmaxf.rs index ac0d22aa5..a883fdaef 100644 --- a/src/math/maxf.rs +++ b/src/math/fmaxf.rs @@ -1,6 +1,6 @@ #[inline] #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn maxf(x: f32, y: f32) -> f32 { +pub fn fmaxf(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). diff --git a/src/math/min.rs b/src/math/fmin.rs similarity index 95% rename from src/math/min.rs rename to src/math/fmin.rs index d0345cf8d..d1ccc3a46 100644 --- a/src/math/min.rs +++ b/src/math/fmin.rs @@ -1,6 +1,6 @@ #[inline] #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn min(x: f64, y: f64) -> f64 { +pub fn fmin(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). diff --git a/src/math/minf.rs b/src/math/fminf.rs similarity index 95% rename from src/math/minf.rs rename to src/math/fminf.rs index 2098a2d75..43ec97cb5 100644 --- a/src/math/minf.rs +++ b/src/math/fminf.rs @@ -1,6 +1,6 @@ #[inline] #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn minf(x: f32, y: f32) -> f32 { +pub fn fminf(x: f32, y: f32) -> f32 { // 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). diff --git a/src/math/mod.rs b/src/math/mod.rs index bedc3a69e..35ffe1a2c 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -112,6 +112,10 @@ mod floor; mod floorf; mod fma; mod fmaf; +mod fmax; +mod fmaxf; +mod fmin; +mod fminf; mod fmod; mod fmodf; mod frexp; @@ -140,10 +144,6 @@ mod log1pf; mod log2; mod log2f; mod logf; -mod max; -mod maxf; -mod min; -mod minf; mod modf; mod modff; mod pow; @@ -216,6 +216,10 @@ pub use self::floor::floor; pub use self::floorf::floorf; pub use self::fma::fma; pub use self::fmaf::fmaf; +pub use self::fmax::fmax; +pub use self::fmaxf::fmaxf; +pub use self::fmin::fmin; +pub use self::fminf::fminf; pub use self::fmod::fmod; pub use self::fmodf::fmodf; pub use self::frexp::frexp; @@ -250,10 +254,6 @@ pub use self::log1pf::log1pf; pub use self::log2::log2; pub use self::log2f::log2f; pub use self::logf::logf; -pub use self::max::max; -pub use self::maxf::maxf; -pub use self::min::min; -pub use self::minf::minf; pub use self::modf::modf; pub use self::modff::modff; pub use self::pow::pow;