Skip to content

Commit 1b7caab

Browse files
committed
Implement 'Display', 'LowerExp', and 'UpperExp' for 'f128';
1 parent 7ad23f4 commit 1b7caab

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

library/core/src/fmt/float.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ trait GeneralFormat: PartialOrd {
1010
}
1111

1212
macro_rules! impl_general_format {
13-
($($t:ident)*) => {
14-
$(impl GeneralFormat for $t {
13+
($($ty:ty)*) => {
14+
$(impl GeneralFormat for $ty {
1515
fn already_rounded_value_should_use_exponential(&self) -> bool {
16-
let abs = $t::abs(*self);
16+
let abs = <$ty>::abs(*self);
1717
(abs != 0.0 && abs < 1e-4) || abs >= 1e+16
1818
}
1919
})*
@@ -23,6 +23,8 @@ macro_rules! impl_general_format {
2323
#[cfg(target_has_reliable_f16)]
2424
impl_general_format! { f16 }
2525
impl_general_format! { f32 f64 }
26+
#[cfg(target_has_reliable_f128)]
27+
impl_general_format! { f128 }
2628

2729
// Don't inline this so callers don't use the stack space this function
2830
// requires unless they have to.
@@ -198,7 +200,7 @@ where
198200
}
199201

200202
macro_rules! floating {
201-
($($ty:ident)*) => {
203+
($($ty:ty)*) => {
202204
$(
203205
#[stable(feature = "rust1", since = "1.0.0")]
204206
impl Debug for $ty {
@@ -231,10 +233,11 @@ macro_rules! floating {
231233
};
232234
}
233235

234-
floating! { f32 f64 }
235-
236236
#[cfg(target_has_reliable_f16)]
237237
floating! { f16 }
238+
floating! { f32 f64 }
239+
#[cfg(target_has_reliable_f128)]
240+
floating! { f128 }
238241

239242
// FIXME(f16_f128): A fallback is used when the backend+target does not support f16 well, in order
240243
// to avoid ICEs.
@@ -275,10 +278,38 @@ impl UpperExp for f16 {
275278
}
276279
}
277280

281+
#[cfg(not(target_has_reliable_f128))]
278282
#[stable(feature = "rust1", since = "1.0.0")]
279283
impl Debug for f128 {
280284
#[inline]
281285
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
282286
write!(f, "{:#034x}", self.to_bits())
283287
}
284288
}
289+
290+
#[cfg(not(target_has_reliable_f128))]
291+
#[stable(feature = "rust1", since = "1.0.0")]
292+
impl Display for f128 {
293+
#[inline]
294+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
295+
Debug::fmt(self, fmt)
296+
}
297+
}
298+
299+
#[cfg(not(target_has_reliable_f128))]
300+
#[stable(feature = "rust1", since = "1.0.0")]
301+
impl LowerExp for f128 {
302+
#[inline]
303+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
304+
Debug::fmt(self, fmt)
305+
}
306+
}
307+
308+
#[cfg(not(target_has_reliable_f128))]
309+
#[stable(feature = "rust1", since = "1.0.0")]
310+
impl UpperExp for f128 {
311+
#[inline]
312+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
313+
Debug::fmt(self, fmt)
314+
}
315+
}

0 commit comments

Comments
 (0)