From 27454def0ce5fe4cc8999654e7b47cd14239dbe0 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 15 Mar 2018 22:37:12 +0000 Subject: [PATCH] Implement fmt::Binary for f32 and f64 --- src/libcore/fmt/float.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 03e7a9a49d8a7..27d80a3d48d72 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use fmt::{Formatter, Result, LowerExp, UpperExp, Display, Debug}; +use fmt::{Formatter, Result, LowerExp, UpperExp, Display, Debug, Binary}; use mem; -use num::flt2dec; +use num::{flt2dec, Float}; // Don't inline this so callers don't use the stack space this function // requires unless they have to. @@ -150,6 +150,13 @@ macro_rules! floating { float_to_exponential_common(fmt, self, true) } } + + #[stable(feature = "floating_point_binary_fmt", since = "1.26.0")] + impl Binary for $ty { + fn fmt(&self, fmt: &mut Formatter) -> Result { + write!(fmt, "{:01$b}", self.to_bits(), 8 * mem::size_of::<$ty>()) + } + } ) }