summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChip Salzenberg <chip@perl.com>1997-03-22 12:40:20 +1200
committerChip Salzenberg <chip@atlantic.net>1997-03-22 15:34:25 +1200
commitbeb185056790fb74a315834bcd0fdb296a71c854 (patch)
tree01a7254ae64ddb27822978b88a08a35e2c825678
parent4b65379bc43430e952dd16dee404322de24998dc (diff)
downloadperl-beb185056790fb74a315834bcd0fdb296a71c854.tar.gz
Refine modulus ("%") per suggestion of Tim Goodwin
-rw-r--r--pp.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/pp.c b/pp.c
index e3ed078896..a988646c58 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;
}
}