From aea5ec50c984d0badfb773492941980be7177a71 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 11 Feb 2021 21:46:11 +0800 Subject: [PATCH] Fix no-std build. --- src/ast.rs | 3 +++ src/packages/string_basic.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index bcfd7e70..77c001ff 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1176,6 +1176,9 @@ impl fmt::Debug for FloatWrapper { #[cfg(not(feature = "no_float"))] impl fmt::Display for FloatWrapper { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + #[cfg(feature = "no_std")] + use num_traits::Float; + let abs = self.0.abs(); if abs > 10000000000000.0 || abs < 0.0000000000001 { write!(f, "{:e}", self.0) diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index 6488e8c1..1442a161 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -83,6 +83,9 @@ fn to_debug(x: &mut T) -> ImmutableString { } #[cfg(not(feature = "no_float"))] fn print_f64(x: &mut f64) -> ImmutableString { + #[cfg(feature = "no_std")] + use num_traits::Float; + let abs = x.abs(); if abs > 10000000000000.0 || abs < 0.0000000000001 { format!("{:e}", x).into() @@ -92,6 +95,9 @@ fn print_f64(x: &mut f64) -> ImmutableString { } #[cfg(not(feature = "no_float"))] fn print_f32(x: &mut f32) -> ImmutableString { + #[cfg(feature = "no_std")] + use num_traits::Float; + let abs = x.abs(); if abs > 10000000000000.0 || abs < 0.0000000000001 { format!("{:e}", x).into()