aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-05-16 09:40:36 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-05-16 09:40:36 +0200
commit1113961dde21ce73c1543ca466913d9e17d06c1b (patch)
tree2956a47d072fd613c05d2a31f4f363addc64e8f5 /miscutils
parentabe248b20880d4d3831ba0a188f69d4a8126498a (diff)
downloadbusybox-1113961dde21ce73c1543ca466913d9e17d06c1b.tar.gz
dc: make 4 % 0 emit error messgaes and set result to 0
function old new delta mod 105 136 +31 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/dc.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/miscutils/dc.c b/miscutils/dc.c
index 5119c1383..5aef64b60 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -94,13 +94,18 @@ static void mod(void)
{
data_t d = pop();
- //if (d == 0) {
- // bb_error_msg("remainder by zero");
- // pop();
- // push(0);
- // return;
- //}
- //^^^^ without this, we simply get SIGFPE and die
+ /* compat with dc (GNU bc 1.07.1) 1.4.1:
+ * $ dc -e '4 0 % p'
+ * dc: remainder by zero
+ * 0
+ */
+ if (d == 0) {
+ bb_error_msg("remainder by zero");
+ pop();
+ push(0);
+ return;
+ }
+ /* ^^^^ without this, we simply get SIGFPE and die */
push((data_t) pop() % d);
}