From 5bcedcff4c03f023f5423bc46a7a708888166266 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Fri, 16 Jul 2021 23:32:18 +0300 Subject: Round very small values to zero in tick labels. Sometimes, due to representation errors, we have an axis boundary that should be zero but is actually negative and very small. In order to avoid printing "-0" we round off these values to zero. --- src/renderer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/renderer.cpp b/src/renderer.cpp index 8c762e2..31e5c51 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -32,6 +32,12 @@ ValueToShortString(double value, int prec, const std::string& unit) prec++; + /* round very low values to zero */ + /* theoretically this function should not be asked to print values as small as 1e-9 */ + if (std::abs(value) < 1e-9) { + value = 0.0; + } + std::stringstream ss; ss << std::fixed << std::setprecision(prec > 0 ? prec : 0) << value << PREFIXES[pidx] << unit; return ss.str(); -- cgit v1.2.3