{
dSP; dATARGET; tryAMAGICbin(mod,opASSIGN);
{
- register unsigned long tmpulong;
- register long tmplong;
- I32 value;
+ register IV value;
+ register UV uval;
- tmpulong = (unsigned long) POPn;
- if (tmpulong == 0L)
+ uval = POPn;
+ if (!uval)
DIE("Illegal modulus zero");
value = TOPn;
- if (value >= 0.0)
- value = (I32)(((unsigned long)value) % tmpulong);
+ if (value >= 0)
+ value = (UV)value % uval;
else {
- tmplong = (long)value;
- value = (I32)(tmpulong - ((-tmplong - 1) % tmpulong)) - 1;
+ value = (uval - ((UV)(-value - 1) % uval)) - 1;
}
SETi(value);
RETURN;
if (SvNIOKp(left) || SvNIOKp(right)) {
unsigned long value = U_L(SvNV(left));
value = value & U_L(SvNV(right));
- SETn((double)value);
+ if ((IV)value == value)
+ SETi(value);
+ else
+ SETn((double)value);
}
else {
do_vop(op->op_type, TARG, left, right);
if (SvNIOKp(left) || SvNIOKp(right)) {
unsigned long value = U_L(SvNV(left));
value = value ^ U_L(SvNV(right));
- SETn((double)value);
+ if ((IV)value == value)
+ SETi(value);
+ else
+ SETn((double)value);
}
else {
do_vop(op->op_type, TARG, left, right);
if (SvNIOKp(left) || SvNIOKp(right)) {
unsigned long value = U_L(SvNV(left));
value = value | U_L(SvNV(right));
- SETn((double)value);
+ if ((IV)value == value)
+ SETi(value);
+ else
+ SETn((double)value);
}
else {
do_vop(op->op_type, TARG, left, right);
register I32 anum;
if (SvNIOKp(sv)) {
- IV iv = ~SvIV(sv);
- if (iv < 0)
- SETn( (double) ~U_L(SvNV(sv)) );
+ UV value = ~SvIV(sv);
+ if ((IV)value == value)
+ SETi(value);
else
- SETi( iv );
+ SETn((double)value);
}
else {
register char *tmps;
Copy(s, &auint, 1, unsigned int);
s += sizeof(unsigned int);
sv = NEWSV(41, 0);
- sv_setiv(sv, (I32)auint);
+ if (auint <= I32_MAX)
+ sv_setiv(sv, (I32)auint);
+ else
+ sv_setnv(sv, (double)auint);
PUSHs(sv_2mortal(sv));
}
}