fix(bkgpslog):Fix float calc in buffer PID adjust
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 7 Jul 2020 09:59:26 +0000 (09:59 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 7 Jul 2020 09:59:26 +0000 (09:59 +0000)
exec/bkgpslog

index 9e23f015762268736bd5cd11901bce028c213eba..7a4487fd872bfcea28fbf833f56ae1181fff5b09 100755 (executable)
@@ -999,7 +999,10 @@ magicBufferSleepPID() {
        yell "WARNING:Buffer lag adjustment yielded negative seconds.";
     fi;
     ## Calculate nanosecond remainder
-    BUFFER_TTL_ADJ_FLOATFRAC="$((BUFFER_TTL_NS - (BUFFER_TTL_ADJ_INT*(10**9)) ))" && vbm "BUFFER_TTL_ADJ_FLOATFRAC:$BUFFER_TTL_ADJ_FLOATFRAC";
+    ### Remove integer
+    BUFFER_TTL_ADJ_FLOATFRAC="$((BUFFER_TTL_ADJ_NS - (BUFFER_TTL_ADJ_INT*(10**9)) ))";
+    ### Calc absolute value of fraction (by removing '-' if present; see https://stackoverflow.com/a/47240327
+    BUFFER_TTL_ADJ_FLOATFRAC="${BUFFER_TTL_ADJ_FLOAT_FRAC#-}" && vbm "BUFFER_TTL_ADJ_FLOATFRAC:$BUFFER_TTL_ADJ_FLOATFRAC";
     ## Form float BUFFER_TTL_ADJ_FLOAT
     BUFFER_TTL_ADJ_FLOAT="$BUFFER_TTL_ADJ_INT"."$BUFFER_TTL_ADJ_FLOATFRAC" && vbm "BUFFER_TTL_ADJ_FLOAT:$BUFFER_TTL_ADJ_FLOAT";
     vbm "STATUS:Calculated adjusted BUFFER_TTL (seconds):$BUFFER_TTL_ADJ_FLOAT";