]> Repositorios git - scryer-prolog.git/commitdiff
fix float formatting (#1233, #1258)
authorMark Thom <[email protected]>
Fri, 4 Feb 2022 02:57:41 +0000 (19:57 -0700)
committerMark Thom <[email protected]>
Sun, 6 Feb 2022 01:33:27 +0000 (18:33 -0700)
src/heap_print.rs

index 40afdbfcadd0f5d3955e4045a28a3b13174842e6..8852c3c83041d534560867ca08ac93ea86bf65e8 100644 (file)
@@ -938,10 +938,20 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
                         fl = 0f64;
                     }
 
-                    let output_str = format!("{0:<20?}", fl);
+                    let output_str = if fl.fract() == 0f64 {
+                        if fl.abs() >= 1.0e16 {
+                            format!("{:.1e}", fl.trunc())
+                        } else {
+                            format!("{:.1}", fl.trunc())
+                        }
+                    } else if 0f64 < fl.fract().abs() && fl.fract().abs() <= 1.0e-16 {
+                        format!("{:>1e}", fl)
+                    } else {
+                        format!("{}", fl)
+                    };
 
                     push_space_if_amb!(self, &output_str, {
-                        append_str!(self, &output_str.trim());
+                        append_str!(self, &output_str);
                     });
                 }
                 Number::Rational(r) => {