summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasile Vilvoiu <vasi@vilvoiu.ro>2021-07-16 23:32:18 +0300
committerVasile Vilvoiu <vasi@vilvoiu.ro>2021-07-16 23:32:18 +0300
commit5bcedcff4c03f023f5423bc46a7a708888166266 (patch)
treee014d29b4c5e0a237de9545c03721f55c35e5a60
parentb2ce4c9758b717be4f416507fb31d88855406171 (diff)
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.
-rw-r--r--src/renderer.cpp6
1 files changed, 6 insertions, 0 deletions
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();