about summary refs log tree commit diff
path: root/library/compiler-builtins/libm/src/math/generic/fmaximum_num.rs
blob: 2dc60b2d237f5371d75315ed82cb95765aa8c9a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* SPDX-License-Identifier: MIT OR Apache-2.0 */
//! IEEE 754-2019 `maximumNumber`.
//!
//! Per the spec, returns:
//! - `x` if `x > y`
//! - `y` if `y > x`
//! - +0.0 if x and y are zero with opposite signs
//! - Either `x` or `y` if `x == y` and the signs are the same
//! - Non-NaN if one operand is NaN
//! - qNaN if both operands are NaNx
//!
//! 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 > y || y.is_nan() {
        x
    } else if y > x || x.is_nan() {
        y
    } else if x.is_sign_positive() {
        x
    } else {
        y
    };

    res.canonicalize()
}