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;
|
||||
|
||||
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
|
||||
}
|
||||
if x <= y { F::ZERO } else { x - y }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user