Skip to content

Commit

Permalink
bc: divide by 0 (#580)
Browse files Browse the repository at this point in the history
* Catch illegal division before it happens
* In bignum mode an error would not be thrown previously for this case; testing with is_zero() resolves this
* I tested this in interactive mode for -b and not-b; the die() is caught so bc does not terminate---this is consistent with GNU bc
  • Loading branch information
mknos committed Apr 26, 2024
1 parent 1038b0e commit b8e3715
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bin/bc
Expand Up @@ -2334,7 +2334,7 @@ sub exec_stmt
if ($_ eq '+_') { $res = $a + $b ; 1 }
elsif($_ eq '-_') { $res = $a - $b ; 1 }
elsif($_ eq '*_') { $res = $a * $b ; 1 }
elsif($_ eq '/_') { $res = $a / $b ; 1 }
elsif($_ eq '/_') { die 'divide by 0' if ($bignum ? $b->is_zero : $b == 0); $res = $a / $b }
elsif($_ eq '^_') { $res = $a ** $b ; 1 }
elsif($_ eq '%_') { $res = $a % $b ; 1 }

Expand Down

0 comments on commit b8e3715

Please sign in to comment.