Skip to content

Commit 2b8045a

Browse files
authored
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.
1 parent ebbd4c1 commit 2b8045a

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/math/generic/fdim.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
use super::super::Float;
22

33
pub fn fdim<F: Float>(x: F, y: F) -> F {
4-
if x.is_nan() {
5-
x
6-
} else if y.is_nan() {
7-
y
8-
} else if x > y {
9-
x - y
10-
} else {
11-
F::ZERO
12-
}
4+
if x <= y { F::ZERO } else { x - y }
135
}

0 commit comments

Comments
 (0)