From ea8a3ea7d228dffa61acf21e7859c758612edd88 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 1 May 2020 17:27:13 +0200 Subject: [PATCH] nicer print for cld --- hprint.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hprint.cpp b/hprint.cpp index 43dac30a..706677e6 100644 --- a/hprint.cpp +++ b/hprint.cpp @@ -279,7 +279,21 @@ struct indenter_finish : indenter { #endif -EX void print(hstream& hs, cld x) { print(hs, real(x)); if(kz(imag(x))) print(hs, "+", imag(x), "i"); } +EX void print(hstream& hs, cld x) { + int parts = 0; + if(kz(real(x))) { + print(hs, real(x)); + parts++; + } + + if(kz(imag(x))) { + if(parts && imag(x) > 0) print(hs, "+"); + parts++; + print(hs, imag(x), "i"); + } + + if(!parts) print(hs, 0); + } EX string fts_fixed(ld x, int prec IS(6)) { std::stringstream ss;