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:
quaternic
2025-01-14 03:55:26 +02:00
committed by GitHub
parent 72ec4b39ca
commit bfbe919adf

View File

@@ -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
}
} }