From a0dd0550ad0ce6c2685b4449dac69e8816d8c7af Mon Sep 17 00:00:00 2001 From: Benjamin Schultzer Date: Wed, 3 Jul 2019 11:57:54 -0700 Subject: [PATCH 1/2] Add remainder This PR adds the missing `remainder` and `remainderf` found in musl libm respectly https://git.musl-libc.org/cgit/musl/tree/src/math/remainder.c and https://git.musl-libc.org/cgit/musl/tree/src/math/remainderf.c Signed-off-by: Benjamin Schultzer --- src/math/mod.rs | 4 ++++ src/math/remainder.rs | 5 +++++ src/math/remainderf.rs | 5 +++++ 3 files changed, 14 insertions(+) create mode 100644 src/math/remainder.rs create mode 100644 src/math/remainderf.rs diff --git a/src/math/mod.rs b/src/math/mod.rs index 35ffe1a..48b400a 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -148,6 +148,8 @@ mod modf; mod modff; mod pow; mod powf; +mod remainder; +mod remainderf; mod remquo; mod remquof; mod round; @@ -258,6 +260,8 @@ pub use self::modf::modf; pub use self::modff::modff; pub use self::pow::pow; pub use self::powf::powf; +pub use self::remainder::remainder; +pub use self::remainderf::remainderf; pub use self::remquo::remquo; pub use self::remquof::remquof; pub use self::round::round; diff --git a/src/math/remainder.rs b/src/math/remainder.rs new file mode 100644 index 0000000..e0f56da --- /dev/null +++ b/src/math/remainder.rs @@ -0,0 +1,5 @@ +#[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn remainder(x: f64, y: f64) -> (f64, i32) { + super::remquo(x, y) +} diff --git a/src/math/remainderf.rs b/src/math/remainderf.rs new file mode 100644 index 0000000..72fd0e2 --- /dev/null +++ b/src/math/remainderf.rs @@ -0,0 +1,5 @@ +#[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn remainderf(x: f32, y: f32) -> (f32, i32) { + super::remquof(x, y) +} From da9c12b2da43956e8ccf4e2950fb5d53b32e6cc2 Mon Sep 17 00:00:00 2001 From: Benjamin Schultzer Date: Wed, 3 Jul 2019 14:15:29 -0700 Subject: [PATCH 2/2] Only return the fp value. Signed-off-by: Benjamin Schultzer --- src/math/remainder.rs | 5 +++-- src/math/remainderf.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/math/remainder.rs b/src/math/remainder.rs index e0f56da..7ce8950 100644 --- a/src/math/remainder.rs +++ b/src/math/remainder.rs @@ -1,5 +1,6 @@ #[inline] #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn remainder(x: f64, y: f64) -> (f64, i32) { - super::remquo(x, y) +pub fn remainder(x: f64, y: f64) -> f64 { + let (result, _) = super::remquo(x, y); + result } diff --git a/src/math/remainderf.rs b/src/math/remainderf.rs index 72fd0e2..8b2aa5a 100644 --- a/src/math/remainderf.rs +++ b/src/math/remainderf.rs @@ -1,5 +1,6 @@ #[inline] #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn remainderf(x: f32, y: f32) -> (f32, i32) { - super::remquof(x, y) +pub fn remainderf(x: f32, y: f32) -> f32 { + let (result, _) = super::remquof(x, y); + result }