diff options
author | Chip Salzenberg <chip@perl.com> | 1997-03-22 12:40:20 +1200 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-03-22 15:34:25 +1200 |
commit | beb185056790fb74a315834bcd0fdb296a71c854 (patch) | |
tree | 01a7254ae64ddb27822978b88a08a35e2c825678 | |
parent | 4b65379bc43430e952dd16dee404322de24998dc (diff) | |
download | perl-beb185056790fb74a315834bcd0fdb296a71c854.tar.gz |
Refine modulus ("%") per suggestion of Tim Goodwin
-rw-r--r-- | pp.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -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; } } |