Add a generic version of fdim

This commit is contained in:
Trevor Gross 2025-01-13 13:49:43 +00:00
parent 23dfe62a9d
commit 0f285df716
5 changed files with 21 additions and 24 deletions

View file

@ -289,13 +289,15 @@
"fdim": {
"sources": [
"src/libm_helper.rs",
"src/math/fdim.rs"
"src/math/fdim.rs",
"src/math/generic/fdim.rs"
],
"type": "f64"
},
"fdimf": {
"sources": [
"src/math/fdimf.rs"
"src/math/fdimf.rs",
"src/math/generic/fdim.rs"
],
"type": "f32"
},

View file

@ -1,5 +1,3 @@
use core::f64;
/// Positive difference (f64)
///
/// Determines the positive difference between arguments, returning:
@ -10,13 +8,5 @@ use core::f64;
/// A range error may occur.
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
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
}
super::generic::fdim(x, y)
}

View file

@ -1,5 +1,3 @@
use core::f32;
/// Positive difference (f32)
///
/// Determines the positive difference between arguments, returning:
@ -10,13 +8,5 @@ use core::f32;
/// A range error may occur.
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
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
}
super::generic::fdim(x, y)
}

View file

@ -0,0 +1,13 @@
use super::super::Float;
pub fn fdim<F: Float>(x: F, y: F) -> F {
if x.is_nan() {
x
} else if y.is_nan() {
y
} else if x > y {
x - y
} else {
F::ZERO
}
}

View file

@ -1,7 +1,9 @@
mod copysign;
mod fabs;
mod fdim;
mod trunc;
pub use copysign::copysign;
pub use fabs::fabs;
pub use fdim::fdim;
pub use trunc::trunc;