X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Futil.cpp;h=029ae079b64fcea1253bc66ed5fead8f7969f757;hb=ca810a8ce1f0257e78ad00bc8f794c68f7438cad;hp=6772b040defddb3660e4cb46d52019a737f1456e;hpb=6638455fc549fa58666a40e14ec5de40f20e2147;p=pulseview.git diff --git a/pv/util.cpp b/pv/util.cpp index 6772b04..029ae07 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) @@ -118,7 +119,7 @@ static QString format_time_in_full(double t, signed precision, bool force_sign) if (precision >= 0) { ts << pad_number(seconds, use_padding ? 2 : 0); - const double fraction = fabs(t - whole_seconds); + const double fraction = fabs(t) - whole_seconds; if (precision > 0 && precision < 1000) { QString fs = QString("%1").arg(fraction, -(2 + precision), 'f', @@ -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);