about summary refs log tree commit diff
path: root/library/compiler-builtins/libm/src/math/generic/copysign.rs
blob: da9ce3878852103e68077a5479770ba36e349211 (plain)
1
2
3
4
5
6
7
8
9
10
11
use crate::support::Float;

/// Copy the sign of `y` to `x`.
#[inline]
pub fn copysign<F: Float>(x: F, y: F) -> F {
    let mut ux = x.to_bits();
    let uy = y.to_bits();
    ux &= !F::SIGN_MASK;
    ux |= uy & F::SIGN_MASK;
    F::from_bits(ux)
}