Fix no-std build.

This commit is contained in:
Stephen Chung 2021-02-11 21:46:11 +08:00
parent 6f71367c15
commit aea5ec50c9
2 changed files with 9 additions and 0 deletions

View File

@ -1176,6 +1176,9 @@ impl fmt::Debug for FloatWrapper {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
impl fmt::Display for FloatWrapper { impl fmt::Display for FloatWrapper {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(feature = "no_std")]
use num_traits::Float;
let abs = self.0.abs(); let abs = self.0.abs();
if abs > 10000000000000.0 || abs < 0.0000000000001 { if abs > 10000000000000.0 || abs < 0.0000000000001 {
write!(f, "{:e}", self.0) write!(f, "{:e}", self.0)

View File

@ -83,6 +83,9 @@ fn to_debug<T: Debug>(x: &mut T) -> ImmutableString {
} }
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
fn print_f64(x: &mut f64) -> ImmutableString { fn print_f64(x: &mut f64) -> ImmutableString {
#[cfg(feature = "no_std")]
use num_traits::Float;
let abs = x.abs(); let abs = x.abs();
if abs > 10000000000000.0 || abs < 0.0000000000001 { if abs > 10000000000000.0 || abs < 0.0000000000001 {
format!("{:e}", x).into() format!("{:e}", x).into()
@ -92,6 +95,9 @@ fn print_f64(x: &mut f64) -> ImmutableString {
} }
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
fn print_f32(x: &mut f32) -> ImmutableString { fn print_f32(x: &mut f32) -> ImmutableString {
#[cfg(feature = "no_std")]
use num_traits::Float;
let abs = x.abs(); let abs = x.abs();
if abs > 10000000000000.0 || abs < 0.0000000000001 { if abs > 10000000000000.0 || abs < 0.0000000000001 {
format!("{:e}", x).into() format!("{:e}", x).into()