From: Soeren Apel Date: Wed, 12 Aug 2015 15:34:09 +0000 (+0200) Subject: Util: Fix issue where t=0 randomly shows up as +0 or -0 X-Git-Tag: pulseview-0.3.0~144 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f4ebff5e030af58fdb60d5aa4bf076d2a42d187f;p=pulseview.git Util: Fix issue where t=0 randomly shows up as +0 or -0 --- 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);