changeset 1268:b7b84ae5f0a7 3.0-integration

Fix fairly obscure mis-canonicalisation in RealTime (leading to non-canonical but still correct values)
author Chris Cannam
date Fri, 18 Nov 2016 12:53:21 +0000
parents 1d8418cca63a
children f50c0bbe9096
files base/RealTimeSV.cpp base/test/TestOurRealTime.h
diffstat 2 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/base/RealTimeSV.cpp	Thu Nov 17 14:46:03 2016 +0000
+++ b/base/RealTimeSV.cpp	Fri Nov 18 12:53:21 2016 +0000
@@ -48,10 +48,10 @@
 	while (nsec >=  ONE_BILLION) { nsec -= ONE_BILLION; ++sec; }
     } else if (sec < 0) {
 	while (nsec <= -ONE_BILLION) { nsec += ONE_BILLION; --sec; }
-	while (nsec > 0)             { nsec -= ONE_BILLION; ++sec; }
+	while (nsec > 0 && sec < 0)  { nsec -= ONE_BILLION; ++sec; }
     } else { 
 	while (nsec >=  ONE_BILLION) { nsec -= ONE_BILLION; ++sec; }
-	while (nsec < 0)             { nsec += ONE_BILLION; --sec; }
+	while (nsec < 0 && sec > 0)  { nsec += ONE_BILLION; --sec; }
     }
 }
 
--- a/base/test/TestOurRealTime.h	Thu Nov 17 14:46:03 2016 +0000
+++ b/base/test/TestOurRealTime.h	Fri Nov 18 12:53:21 2016 +0000
@@ -62,6 +62,9 @@
 	QCOMPARE(RealTime(-1, ONE_BILLION), RealTime(0, 0));
 	QCOMPARE(RealTime(-1, -ONE_BILLION), RealTime(-2, 0));
 
+        QCOMPARE(RealTime(1, -ONE_BILLION-ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
+        QCOMPARE(RealTime(-1, ONE_BILLION+ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
+            
 	QCOMPARE(RealTime(2, -ONE_BILLION*2), RealTime(0, 0));
 	QCOMPARE(RealTime(2, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));