const_soft_float/soft_f32/copysign.rs
1use super::SoftF32;
2
3/// Sign of Y, magnitude of X (SoftF32)
4///
5/// Constructs a number with the magnitude (absolute value) of its
6/// first argument, `x`, and the sign of its second argument, `y`.
7pub(crate) const fn copysign(x: SoftF32, y: SoftF32) -> SoftF32 {
8 let mut ux = x.to_bits();
9 let uy = y.to_bits();
10 ux &= 0x7fffffff;
11 ux |= uy & 0x80000000;
12 SoftF32::from_bits(ux)
13}
14
15#[cfg(test)]
16mod test {
17 use super::*;
18
19 #[test]
20 fn sanity_check() {
21 assert_eq!(SoftF32(1.0).copysign(SoftF32(-0.0)).0, -1.0)
22 }
23}