use integer;
-use Test::More tests => 12;
+use Test::More tests => 15;
use Config;
my $x = 4.5;
# [perl #38485] use integer; 0x80000000/-1;
SKIP: {
my $ivsize = $Config{ivsize};
- skip "ivsize == $ivsize", 2 unless $ivsize == 4 || $ivsize == 8;
+ skip "ivsize == $ivsize", 4 unless $ivsize == 4 || $ivsize == 8;
my $iv_min = $ivsize == 4 ? -2147483648 : -9223372036854775808;
my $biff;
eval { $biff = $iv_min / -1 };
- like($@, qr/Integer overflow in division/, "Caught IV_MIN / -1");
+ is($@, '', 'IV_MIN / -1 succeeds');
+ is($biff, -$iv_min, 'IV_MIN / -1 == -IV_MIN');
+
+ eval { $biff = $iv_min % -1 };
+ is($@, '', 'IV_MIN % -1 succeeds');
+ is($biff, 0, 'IV_MIN % -1 == 0');
}
if (value == 0)
DIE(aTHX_ "Illegal division by zero");
num = POPi;
- if (num == IV_MIN && value == -1)
- DIE(aTHX_ "Integer overflow in division");
- value = num / value;
+
+ /* avoid FPE_INTOVF on some platforms when num is IV_MIN */
+ if (value == -1)
+ value = - num;
+ else
+ value = num / value;
PUSHi( value );
RETURN;
}
dPOPTOPiirl;
if (!right)
DIE(aTHX_ "Illegal modulus zero");
- SETi( left % right );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % right );
RETURN;
}
}
dPOPTOPiirl;
if (!right)
DIE(aTHX_ "Illegal modulus zero");
- SETi( left % PERL_ABS(right) );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % PERL_ABS(right) );
RETURN;
}
}
}
}
#endif
- SETi( left % right );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % right );
RETURN;
}
}