diff options
Diffstat (limited to 'library/compiler-builtins/libm/src/math/generic/fmaximum_num.rs')
| -rw-r--r-- | library/compiler-builtins/libm/src/math/generic/fmaximum_num.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/library/compiler-builtins/libm/src/math/generic/fmaximum_num.rs b/library/compiler-builtins/libm/src/math/generic/fmaximum_num.rs new file mode 100644 index 00000000000..05df6cbd464 --- /dev/null +++ b/library/compiler-builtins/libm/src/math/generic/fmaximum_num.rs @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: MIT OR Apache-2.0 */ +//! IEEE 754-2019 `maximumNumber`. +//! +//! Per the spec, returns: +//! - `x` if `x > y` +//! - `y` if `y > x` +//! - Non-NaN if one operand is NaN +//! - Logic following +0.0 > -0.0 +//! - Either `x` or `y` if `x == y` and the signs are the same +//! - qNaN if either operand is a NaN +//! +//! Excluded from our implementation is sNaN handling. + +use crate::support::Float; + +#[inline] +pub fn fmaximum_num<F: Float>(x: F, y: F) -> F { + let res = if x.is_nan() || x < y || (x.biteq(F::NEG_ZERO) && y.is_sign_positive()) { + y + } else { + x + }; + + // Canonicalize + res * F::ONE +} |
