diff --git a/library/core/src/fmt/float.rs b/library/core/src/fmt/float.rs index 556db239f2499..0fff1d25c4d00 100644 --- a/library/core/src/fmt/float.rs +++ b/library/core/src/fmt/float.rs @@ -10,10 +10,10 @@ trait GeneralFormat: PartialOrd { } macro_rules! impl_general_format { - ($($t:ident)*) => { - $(impl GeneralFormat for $t { + ($($ty:ty)*) => { + $(impl GeneralFormat for $ty { fn already_rounded_value_should_use_exponential(&self) -> bool { - let abs = $t::abs(*self); + let abs = <$ty>::abs(*self); (abs != 0.0 && abs < 1e-4) || abs >= 1e+16 } })* @@ -23,6 +23,8 @@ macro_rules! impl_general_format { #[cfg(target_has_reliable_f16)] impl_general_format! { f16 } impl_general_format! { f32 f64 } +#[cfg(target_has_reliable_f128)] +impl_general_format! { f128 } // Don't inline this so callers don't use the stack space this function // requires unless they have to. @@ -198,7 +200,7 @@ where } macro_rules! floating { - ($($ty:ident)*) => { + ($($ty:ty)*) => { $( #[stable(feature = "rust1", since = "1.0.0")] impl Debug for $ty { @@ -231,10 +233,11 @@ macro_rules! floating { }; } -floating! { f32 f64 } - #[cfg(target_has_reliable_f16)] floating! { f16 } +floating! { f32 f64 } +#[cfg(target_has_reliable_f128)] +floating! { f128 } // FIXME(f16_f128): A fallback is used when the backend+target does not support f16 well, in order // to avoid ICEs. @@ -275,6 +278,7 @@ impl UpperExp for f16 { } } +#[cfg(not(target_has_reliable_f128))] #[stable(feature = "rust1", since = "1.0.0")] impl Debug for f128 { #[inline] @@ -282,3 +286,30 @@ impl Debug for f128 { write!(f, "{:#034x}", self.to_bits()) } } + +#[cfg(not(target_has_reliable_f128))] +#[stable(feature = "rust1", since = "1.0.0")] +impl Display for f128 { + #[inline] + fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { + Debug::fmt(self, fmt) + } +} + +#[cfg(not(target_has_reliable_f128))] +#[stable(feature = "rust1", since = "1.0.0")] +impl LowerExp for f128 { + #[inline] + fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { + Debug::fmt(self, fmt) + } +} + +#[cfg(not(target_has_reliable_f128))] +#[stable(feature = "rust1", since = "1.0.0")] +impl UpperExp for f128 { + #[inline] + fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { + Debug::fmt(self, fmt) + } +} diff --git a/library/core/src/num/flt2dec/decoder.rs b/library/core/src/num/flt2dec/decoder.rs index bd6e2cdbafec8..c2c9e83132cc1 100644 --- a/library/core/src/num/flt2dec/decoder.rs +++ b/library/core/src/num/flt2dec/decoder.rs @@ -64,6 +64,13 @@ impl DecodableFloat for f64 { } } +#[cfg(target_has_reliable_f128)] +impl DecodableFloat for f128 { + fn min_pos_norm_value() -> Self { + f128::MIN_POSITIVE + } +} + /// Returns a sign (true when negative) and `FullDecoded` value /// from given floating point number. pub fn decode(v: T) -> (/*negative?*/ bool, FullDecoded) {