Simplify and optimize fdim (#442)
The cases with NaN arguments can be handled by the same x - y expression, and this generates much better code: https://godbolt.org/z/f3rnT8jx4.
This commit is contained in:
@@ -1,13 +1,5 @@
|
|||||||
use super::super::Float;
|
use super::super::Float;
|
||||||
|
|
||||||
pub fn fdim<F: Float>(x: F, y: F) -> F {
|
pub fn fdim<F: Float>(x: F, y: F) -> F {
|
||||||
if x.is_nan() {
|
if x <= y { F::ZERO } else { x - y }
|
||||||
x
|
|
||||||
} else if y.is_nan() {
|
|
||||||
y
|
|
||||||
} else if x > y {
|
|
||||||
x - y
|
|
||||||
} else {
|
|
||||||
F::ZERO
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user