1/// Sign of Y, magnitude of X (f16)
2///
3/// Constructs a number with the magnitude (absolute value) of its
4/// first argument, `x`, and the sign of its second argument, `y`.
5#[cfg(f16_enabled)]
6#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
7pub fn copysignf16(x: f16, y: f16) -> f16 {
8super::generic::copysign(x, y)
9}
1011/// Sign of Y, magnitude of X (f32)
12///
13/// Constructs a number with the magnitude (absolute value) of its
14/// first argument, `x`, and the sign of its second argument, `y`.
15#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
16pub fn copysignf(x: f32, y: f32) -> f32 {
17super::generic::copysign(x, y)
18}
1920/// Sign of Y, magnitude of X (f64)
21///
22/// Constructs a number with the magnitude (absolute value) of its
23/// first argument, `x`, and the sign of its second argument, `y`.
24#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
25pub fn copysign(x: f64, y: f64) -> f64 {
26super::generic::copysign(x, y)
27}
2829/// Sign of Y, magnitude of X (f128)
30///
31/// Constructs a number with the magnitude (absolute value) of its
32/// first argument, `x`, and the sign of its second argument, `y`.
33#[cfg(f128_enabled)]
34#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
35pub fn copysignf128(x: f128, y: f128) -> f128 {
36super::generic::copysign(x, y)
37}
3839#[cfg(test)]
40mod tests {
41use super::*;
42use crate::support::Float;
4344fn spec_test<F: Float>(f: impl Fn(F, F) -> F) {
45assert_biteq!(f(F::ZERO, F::ZERO), F::ZERO);
46assert_biteq!(f(F::NEG_ZERO, F::ZERO), F::ZERO);
47assert_biteq!(f(F::ZERO, F::NEG_ZERO), F::NEG_ZERO);
48assert_biteq!(f(F::NEG_ZERO, F::NEG_ZERO), F::NEG_ZERO);
4950assert_biteq!(f(F::ONE, F::ONE), F::ONE);
51assert_biteq!(f(F::NEG_ONE, F::ONE), F::ONE);
52assert_biteq!(f(F::ONE, F::NEG_ONE), F::NEG_ONE);
53assert_biteq!(f(F::NEG_ONE, F::NEG_ONE), F::NEG_ONE);
5455assert_biteq!(f(F::INFINITY, F::INFINITY), F::INFINITY);
56assert_biteq!(f(F::NEG_INFINITY, F::INFINITY), F::INFINITY);
57assert_biteq!(f(F::INFINITY, F::NEG_INFINITY), F::NEG_INFINITY);
58assert_biteq!(f(F::NEG_INFINITY, F::NEG_INFINITY), F::NEG_INFINITY);
5960// Not required but we expect it
61assert_biteq!(f(F::NAN, F::NAN), F::NAN);
62assert_biteq!(f(F::NEG_NAN, F::NAN), F::NAN);
63assert_biteq!(f(F::NAN, F::NEG_NAN), F::NEG_NAN);
64assert_biteq!(f(F::NEG_NAN, F::NEG_NAN), F::NEG_NAN);
65 }
6667#[test]
68 #[cfg(f16_enabled)]
69fn spec_tests_f16() {
70 spec_test::<f16>(copysignf16);
71 }
7273#[test]
74fn spec_tests_f32() {
75 spec_test::<f32>(copysignf);
76 }
7778#[test]
79fn spec_tests_f64() {
80 spec_test::<f64>(copysign);
81 }
8283#[test]
84 #[cfg(f128_enabled)]
85fn spec_tests_f128() {
86 spec_test::<f128>(copysignf128);
87 }
88}