| 1 | /* SPDX-License-Identifier: MIT OR Apache-2.0 */ |
| 2 | //! IEEE 754-2019 `maximumNumber`. |
| 3 | //! |
| 4 | //! Per the spec, returns: |
| 5 | //! - `x` if `x > y` |
| 6 | //! - `y` if `y > x` |
| 7 | //! - +0.0 if x and y are zero with opposite signs |
| 8 | //! - Either `x` or `y` if `x == y` and the signs are the same |
| 9 | //! - Non-NaN if one operand is NaN |
| 10 | //! - qNaN if both operands are NaNx |
| 11 | //! |
| 12 | //! Excluded from our implementation is sNaN handling. |
| 13 | |
| 14 | use crate::support::Float; |
| 15 | |
| 16 | #[inline ] |
| 17 | pub fn fmaximum_num<F: Float>(x: F, y: F) -> F { |
| 18 | let res: F = if x > y || y.is_nan() { |
| 19 | x |
| 20 | } else if y > x || x.is_nan() { |
| 21 | y |
| 22 | } else if x.is_sign_positive() { |
| 23 | x |
| 24 | } else { |
| 25 | y |
| 26 | }; |
| 27 | |
| 28 | res.canonicalize() |
| 29 | } |
| 30 | |