From f4ebff5e030af58fdb60d5aa4bf076d2a42d187f Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Wed, 12 Aug 2015 17:34:09 +0200 Subject: [PATCH] Util: Fix issue where t=0 randomly shows up as +0 or -0 --- pv/util.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pv/util.cpp b/pv/util.cpp index 6772b040..133317e0 100644 --- a/pv/util.cpp +++ b/pv/util.cpp @@ -39,6 +39,7 @@ static const QString SIPrefixes[17] = "T", "P", "E", "Z", "Y"}; const int FirstSIPrefix = 8; const int FirstSIPrefixPower = -(FirstSIPrefix * 3); +const double MinTimeDelta = 1e-15; // Anything below 1 fs can be considered zero QString format_si_value(double v, QString unit, int prefix, unsigned int precision, bool sign) @@ -158,6 +159,10 @@ static QString format_time_with_si(double t, QString unit, int prefix, QString format_time(double t, int prefix, TimeUnit unit, unsigned int precision, double step_size, bool sign) { + // Make 0 appear as 0, not random +0 or -0 + if (fabs(t) < MinTimeDelta) + return "0"; + // If we have to use samples then we have no alternative formats if (unit == Samples) return format_time_with_si(t, "sa", prefix, precision, sign); -- 2.30.2