fix sival log for negative/zero values
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 8 Sep 2019 14:44:39 +0000 (16:44 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 9 Sep 2019 22:37:53 +0000 (00:37 +0200)
barcat

diff --git a/barcat b/barcat
index a664d0ddec200f0762e5a3a6ea1d269c5baf571b..48464342d6f2d2053fe28fb1f835ea9b364136c8 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -143,7 +143,7 @@ if ($opt{markers} // 1 and $size > 0) {
 @lines > $nr or return if $opt{hidemin};
 
 sub sival {
-       my $unit = int(log($_[0]) / log(1000) - ($_[0] < 1) + 1e-15);
+       my $unit = int(log(abs $_[0] || 1) / log(1000) - ($_[0] < 1) + 1e-15);
        my $float = sprintf '%e', $_[0] / 1000 ** $unit;  #TODO: or $_[0] =~ /\./
        $float -= int($float);
        sprintf('%*.*f%*s',