From: Chip Salzenberg Date: Sat, 22 Mar 1997 00:40:20 +0000 (+1200) Subject: Refine modulus ("%") per suggestion of Tim Goodwin X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=beb185056790fb74a315834bcd0fdb296a71c854;p=p5sagit%2Fp5-mst-13.2.git Refine modulus ("%") per suggestion of Tim Goodwin --- diff --git a/pp.c b/pp.c index e3ed078..a988646 100644 --- a/pp.c +++ b/pp.c @@ -688,34 +688,43 @@ PP(pp_modulo) { UV left; UV right; - bool negate; + bool left_neg; + bool right_neg; UV ans; if (SvIOK(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)) { IV i = SvIVX(POPs); - right = (i < 0) ? -i : i; + right = (right_neg = (i < 0)) ? -i : i; } else { double n = POPn; - right = U_V((n < 0) ? -n : n); + right = U_V((right_neg = (n < 0)) ? -n : n); } if (SvIOK(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)) { IV i = SvIVX(POPs); - left = (negate = (i < 0)) ? -i : i; + left = (left_neg = (i < 0)) ? -i : i; } else { double n = POPn; - left = U_V((negate = (n < 0)) ? -n : n); + left = U_V((left_neg = (n < 0)) ? -n : n); } if (!right) DIE("Illegal modulus zero"); ans = left % right; - if (negate && ans) + if ((left_neg != right_neg) && ans) ans = right - ans; - PUSHu(ans); + if (right_neg) { + if (ans <= -(UV)IV_MAX) + sv_setiv(TARG, (IV) -ans); + else + sv_setnv(TARG, -(double)ans); + } + else + sv_setuv(TARG, ans); + PUSHTARG; RETURN; } }