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>
This commit is contained in:
Denys Vlasenko 2019-05-16 09:40:36 +02:00
parent abe248b208
commit 1113961dde

View File

@ -94,13 +94,18 @@ static void mod(void)
{ {
data_t d = pop(); data_t d = pop();
//if (d == 0) { /* compat with dc (GNU bc 1.07.1) 1.4.1:
// bb_error_msg("remainder by zero"); * $ dc -e '4 0 % p'
// pop(); * dc: remainder by zero
// push(0); * 0
// return; */
//} if (d == 0) {
//^^^^ without this, we simply get SIGFPE and die bb_error_msg("remainder by zero");
pop();
push(0);
return;
}
/* ^^^^ without this, we simply get SIGFPE and die */
push((data_t) pop() % d); push((data_t) pop() % d);
} }