diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index bcf0f3fc45c29..344f58da277b8 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -132,6 +132,7 @@ pub mod consts { pub const LN_10: f16 = 2.30258509299404568401799145468436421_f16; } +#[doc(test(attr(feature(cfg_target_has_reliable_f16_f128), allow(internal_features))))] impl f16 { // FIXME(f16_f128): almost all methods in this `impl` are missing examples and a const // implementation. Add these once we can run code on all platforms and have f16/f128 in CTFE. @@ -272,7 +273,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let nan = f16::NAN; /// let f = 7.0_f16; @@ -294,7 +295,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 7.0f16; /// let inf = f16::INFINITY; @@ -319,7 +320,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 7.0f16; /// let inf: f16 = f16::INFINITY; @@ -347,7 +348,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let min = f16::MIN_POSITIVE; // 6.1035e-5 /// let max = f16::MAX; @@ -376,7 +377,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let min = f16::MIN_POSITIVE; // 6.1035e-5 /// let max = f16::MAX; @@ -407,7 +408,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// use std::num::FpCategory; /// @@ -443,8 +444,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 7.0_f16; /// let g = -7.0_f16; @@ -472,8 +472,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 7.0_f16; /// let g = -7.0_f16; @@ -507,8 +506,7 @@ impl f16 { /// /// ```rust /// #![feature(f16)] - /// # // FIXME(f16_f128): ABI issues on MSVC - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// // f16::EPSILON is the difference between 1.0 and the next number up. /// assert_eq!(1.0f16.next_up(), 1.0 + f16::EPSILON); @@ -562,8 +560,7 @@ impl f16 { /// /// ```rust /// #![feature(f16)] - /// # // FIXME(f16_f128): ABI issues on MSVC - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// // Clamp value into range [0, 1). @@ -606,8 +603,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 2.0_f16; /// let abs_difference = (x.recip() - (1.0 / x)).abs(); @@ -633,8 +629,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let angle = std::f16::consts::PI; /// @@ -663,8 +658,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let angle = 180.0f16; /// @@ -697,7 +691,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// let y = 2.0f16; @@ -728,7 +722,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// let y = 2.0f16; @@ -760,7 +754,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(float_minimum_maximum)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// let y = 2.0f16; @@ -792,7 +786,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(float_minimum_maximum)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// let y = 2.0f16; @@ -818,7 +812,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// assert_eq!(1f16.midpoint(4.0), 2.5); /// assert_eq!((-5.5f16).midpoint(8.0), 1.25); @@ -848,7 +842,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let value = 4.6_f16; /// let rounded = unsafe { value.to_int_unchecked::() }; @@ -891,7 +885,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// # // FIXME(f16_f128): enable this once const casting works /// # // assert_ne!((1f16).to_bits(), 1f16 as u128); // to_bits() is not casting! @@ -939,7 +933,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let v = f16::from_bits(0x4a40); /// assert_eq!(v, 12.5); @@ -965,8 +959,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let bytes = 12.5f16.to_be_bytes(); /// assert_eq!(bytes, [0x4a, 0x40]); @@ -989,8 +982,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let bytes = 12.5f16.to_le_bytes(); /// assert_eq!(bytes, [0x40, 0x4a]); @@ -1019,8 +1011,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let bytes = 12.5f16.to_ne_bytes(); /// assert_eq!( @@ -1049,7 +1040,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let value = f16::from_be_bytes([0x4a, 0x40]); /// assert_eq!(value, 12.5); @@ -1071,7 +1062,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let value = f16::from_le_bytes([0x40, 0x4a]); /// assert_eq!(value, 12.5); @@ -1100,7 +1091,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let value = f16::from_ne_bytes(if cfg!(target_endian = "big") { /// [0x4a, 0x40] @@ -1150,8 +1141,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// struct GoodBoy { /// name: &'static str, @@ -1234,7 +1224,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// assert!((-3.0f16).clamp(-2.0, 1.0) == -2.0); /// assert!((0.0f16).clamp(-2.0, 1.0) == 0.0); @@ -1285,7 +1275,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(clamp_magnitude)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// assert_eq!(5.0f16.clamp_magnitude(3.0), 3.0); /// assert_eq!((-5.0f16).clamp_magnitude(3.0), -3.0); /// assert_eq!(2.0f16.clamp_magnitude(3.0), 2.0); @@ -1309,7 +1299,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16_math)] { /// /// let x = 3.5_f16; /// let y = -3.5_f16; @@ -1325,8 +1315,7 @@ impl f16 { #[rustc_const_unstable(feature = "f16", issue = "116909")] #[must_use = "method returns a new number and does not mutate the original value"] pub const fn abs(self) -> Self { - // FIXME(f16_f128): replace with `intrinsics::fabsf16` when available - Self::from_bits(self.to_bits() & !(1 << 15)) + intrinsics::fabsf16(self) } /// Returns a number that represents the sign of `self`. @@ -1339,7 +1328,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.5_f16; /// @@ -1375,7 +1364,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16_math)] { /// /// let f = 3.5_f16; /// @@ -1465,7 +1454,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.7_f16; /// let g = 3.0_f16; @@ -1494,7 +1483,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.01_f16; /// let g = 4.0_f16; @@ -1523,7 +1512,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.3_f16; /// let g = -3.3_f16; @@ -1557,7 +1546,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.3_f16; /// let g = -3.3_f16; @@ -1589,7 +1578,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.7_f16; /// let g = 3.0_f16; @@ -1619,7 +1608,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 3.6_f16; /// let y = -3.6_f16; @@ -1658,7 +1647,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let m = 10.0_f16; /// let x = 4.0_f16; @@ -1703,7 +1692,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let a: f16 = 7.0; /// let b = 4.0; @@ -1747,7 +1736,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let a: f16 = 7.0; /// let b = 4.0; @@ -1790,7 +1779,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 2.0_f16; /// let abs_difference = (x.powi(2) - (x * x)).abs(); @@ -1823,7 +1812,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let positive = 4.0_f16; /// let negative = -4.0_f16; @@ -1858,7 +1847,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 8.0f16; ///