round total value slightly in statistics
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 6 Oct 2019 23:51:05 +0000 (01:51 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 8 Oct 2019 00:34:26 +0000 (02:34 +0200)
Compensate for cumulative floating point errors showing up.

barcat
t/t1312-currency-crop_-f,_--value-length=7_--minval=1.1_--maxval=1.11_-L10-30_-s.out
t/t1602-float_statistics_-sL0.out
t/t1901-technicolor_-cs_--header.out
t/t1912-currency_part_-f,_--value-length=7_--minval=1.1_--maxval=1.11_-L10-30_-cs.out

diff --git a/barcat b/barcat
index 5676228584a0b2c42ba644ebc3afd5b3ce97b311..424bec2a979fbf363302e689a467c37fc0b1d2ee 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -277,7 +277,7 @@ sub show_stat {
        }
        if (@order) {
                my $total = sum @order;
-               printf '%s total', color(1) . $total . color(0);
+               printf '%s total', color(1) . sprintf('%.8g', $total) . color(0);
                printf ' in %d values', scalar @order;
                printf ' over %d lines', scalar @lines if @order != @lines;
                printf(' (%s min, %s avg, %s max)',
index e89c5ccf30a618fcfc3880bfdef2e97028c52dec..d188c03aaddbc3e5cec76ecd82fa15c780e77840 100644 (file)
@@ -19,4 +19,4 @@
 2019-08-22 1.1083 ------------------
 2019-08-21 1.1104 -----------------------
 2019-08-20 1.1076 -----------------
-23.1939 of 6386.71270000003 total in 5306 values over 5373 lines (0.8252 min, 1.20 avg, 1.5990 max)
+23.1939 of 6386.7127 total in 5306 values over 5373 lines (0.8252 min, 1.20 avg, 1.5990 max)
index e067ae39f4fc914ef6696389dba4fe14c21ccdac..29557a12b3a0de484d06629ed48933771fe7a27a 100644 (file)
@@ -1 +1 @@
--7.4589999998 total in 16 values over 18 lines (-3 min, -0.47 avg, 2 max)
+-7.459 total in 16 values over 18 lines (-3 min, -0.47 avg, 2 max)
index 415ea1604ff775be79825b661d89b6187ffd269d..8c68b2dc419cae582b25b67a4dcd5062dd41a051 100644 (file)
@@ -17,4 +17,4 @@
 \e[90m          1\e[0m-2     -------\e[36m<\e[0m--\e[36m=\e[0m-\e[36m|\e[0m-----
 \e[90m       -2.0\e[0m       ----
 --1    -------\e[36m<\e[0m--\e[36m=\e[0m-\e[36m|\e[0m
-\e[1m-7.4589999998\e[0m total in 16 values over 18 lines (\e[31m-3\e[0m min, \e[36m-0.47\e[0m avg, \e[32m2\e[0m max)
+\e[1m-7.459\e[0m total in 16 values over 18 lines (\e[31m-3\e[0m min, \e[36m-0.47\e[0m avg, \e[32m2\e[0m max)
index 4ae6263ed653f13cf4fa670eb76be14257216409..f7598ddf5ed2902b09137f0b3074a8ab8fcd463d 100644 (file)
@@ -19,4 +19,4 @@
 2019-08-22\e[90m 1.1083\e[0m ------------------
 2019-08-21\e[32m 1.1104\e[0m -----------------------
 2019-08-20\e[90m 1.1076\e[0m -----------------
-23.1939 of \e[1m6386.71270000003\e[0m total in 5306 values over 5373 lines (\e[31m0.8252\e[0m min, \e[36m1.20\e[0m avg, \e[32m1.5990\e[0m max)
+23.1939 of \e[1m6386.7127\e[0m total in 5306 values over 5373 lines (\e[31m0.8252\e[0m min, \e[36m1.20\e[0m avg, \e[32m1.5990\e[0m max)