From: Mischa POSLAWSKY Date: Sat, 13 Mar 2021 06:16:29 +0000 (+0100) Subject: round partial sum to avoid floating point errors X-Git-Tag: v1.08~19 X-Git-Url: http://git.shiar.nl/barcat.git/commitdiff_plain/d38e0ec883629db7a1b92f379840e7c409bf904e round partial sum to avoid floating point errors Optional value available since commit v1.03-19-g0938debbad (2019-09-08) [indicate limited results in stats] was overlooked while fixing formatting in v1.06-24-g28f38df922 (2019-10-08) [round total value in statistics]. --- diff --git a/barcat b/barcat index 319bc32..0ab19d9 100755 --- a/barcat +++ b/barcat @@ -308,7 +308,7 @@ say $opt{palette} ? color(0) : '' if $opt{spark}; sub show_stat { if ($opt{hidemin} or $opt{hidemax}) { - printf '%s of ', sum(grep { length } + printf '%.8g of ', sum(grep { length } @values[$opt{hidemin} .. ($opt{hidemax} || @lines) - 1] ) // 0; } diff --git a/t/t2180-spark_combined_--spark=012345_-cs_--maxval=1_-L17.out b/t/t2180-spark_combined_--spark=012345_-cs_--maxval=1_-L17.out index df1134e..85a1446 100644 --- a/t/t2180-spark_combined_--spark=012345_-cs_--maxval=1_-L17.out +++ b/t/t2180-spark_combined_--spark=012345_-cs_--maxval=1_-L17.out @@ -1,2 +1,2 @@ 12330443443445043 --7.4589999998 of -7.459 total in 16 values over 18 lines (-3 min, -0.47 avg, 2 max) +-7.459 of -7.459 total in 16 values over 18 lines (-3 min, -0.47 avg, 2 max)