Add a generic version of fdim
This commit is contained in:
parent
23dfe62a9d
commit
0f285df716
5 changed files with 21 additions and 24 deletions
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
13
library/compiler-builtins/libm/src/math/generic/fdim.rs
Normal file
13
library/compiler-builtins/libm/src/math/generic/fdim.rs
Normal 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
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue