1 | /* SPDX-License-Identifier: MIT OR Apache-2.0 */ |
2 | //! IEEE 754-2019 `maximum`. |
3 | //! |
4 | //! Per the spec, returns the canonicalized result of: |
5 | //! - `x` if `x > y` |
6 | //! - `y` if `y > x` |
7 | //! - qNaN if either operation is NaN |
8 | //! - Logic following +0.0 > -0.0 |
9 | //! |
10 | //! Excluded from our implementation is sNaN handling. |
11 | |
12 | use super::super::Float; |
13 | |
14 | #[inline ] |
15 | pub fn fmaximum<F: Float>(x: F, y: F) -> F { |
16 | let res: F = if x.is_nan() { |
17 | x |
18 | } else if y.is_nan() { |
19 | y |
20 | } else if x > y || (y.to_bits() == F::NEG_ZERO.to_bits() && x.is_sign_positive()) { |
21 | x |
22 | } else { |
23 | y |
24 | }; |
25 | |
26 | // Canonicalize |
27 | res * F::ONE |
28 | } |
29 | |