Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fdimf #93

Merged
merged 4 commits into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub trait F32Ext: private::Sealed {

fn trunc(self) -> Self;

fn fdim(self, rhs: Self) -> Self;

#[cfg(todo)]
fn fract(self) -> Self;

Expand Down Expand Up @@ -155,6 +157,11 @@ impl F32Ext for f32 {
truncf(self)
}

#[inline]
fn fdim(self, rhs: Self) -> Self {
fdimf(self, rhs)
}

#[cfg(todo)]
#[inline]
fn fract(self) -> Self {
Expand Down Expand Up @@ -354,6 +361,8 @@ pub trait F64Ext: private::Sealed {

fn trunc(self) -> Self;

fn fdim(self, rhs: Self) -> Self;

#[cfg(todo)]
fn fract(self) -> Self;

Expand Down Expand Up @@ -471,6 +480,10 @@ impl F64Ext for f64 {
trunc(self)
}

#[inline]
fn fdim(self, rhs: Self) -> Self {
fdim(self, rhs)
}
#[cfg(todo)]
#[inline]
fn fract(self) -> Self {
Expand Down
15 changes: 15 additions & 0 deletions src/math/fdim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use core::f64;

pub fn fdim(x: f64, y: f64) -> f64 {
if x.is_nan() {
x
} else if y.is_nan() {
y
} else {
if x > y {
x - y
} else {
0.0
}
}
}
15 changes: 15 additions & 0 deletions src/math/fdimf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use core::f32;

pub fn fdimf(x: f32, y: f32) -> f32 {
if x.is_nan() {
x
} else if y.is_nan() {
y
} else {
if x > y {
x - y
} else {
0.0
}
}
}
5 changes: 2 additions & 3 deletions src/math/fmodf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::f32;
use core::u32;

use super::isnanf;

#[inline]
pub fn fmodf(x: f32, y: f32) -> f32 {
let mut uxi = x.to_bits();
Expand All @@ -11,7 +10,7 @@ pub fn fmodf(x: f32, y: f32) -> f32 {
let sx = uxi & 0x80000000;
let mut i;

if uyi << 1 == 0 || isnanf(y) || ex == 0xff {
if uyi << 1 == 0 || y.is_nan() || ex == 0xff {
return (x * y) / (x * y);
}

Expand Down
8 changes: 4 additions & 4 deletions src/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod cosf;
mod expf;
mod fabs;
mod fabsf;
mod fdim;
mod fdimf;
mod floor;
mod floorf;
mod fmodf;
Expand Down Expand Up @@ -40,6 +42,8 @@ pub use self::cosf::cosf;
pub use self::expf::expf;
pub use self::fabs::fabs;
pub use self::fabsf::fabsf;
pub use self::fdim::fdim;
pub use self::fdimf::fdimf;
pub use self::floor::floor;
pub use self::floorf::floorf;
pub use self::fmodf::fmodf;
Expand Down Expand Up @@ -69,7 +73,3 @@ mod rem_pio2_large;
mod rem_pio2f;

use self::{k_cosf::k_cosf, k_sinf::k_sinf, rem_pio2_large::rem_pio2_large, rem_pio2f::rem_pio2f};

fn isnanf(x: f32) -> bool {
x.to_bits() & 0x7fffffff > 0x7f800000
}
4 changes: 2 additions & 2 deletions test-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ f32_f32! {
// coshf,
// exp2f,
expf,
// fdimf,
log10f,
log1pf,
log2f,
Expand All @@ -679,6 +678,7 @@ f32_f32! {
// With signature `fn(f32, f32) -> f32`
f32f32_f32! {
// atan2f,
fdimf,
hypotf,
fmodf,
powf,
Expand Down Expand Up @@ -724,7 +724,7 @@ f64_f64! {
// With signature `fn(f64, f64) -> f64`
f64f64_f64! {
// atan2,
// fdim,
fdim,
// fmod,
hypot,
// pow,
Expand Down