Prevent floating-point exception if we evaluate $IntMin * (-1)

This commit is contained in:
Dianne Skoll
2021-08-30 12:31:43 -04:00
parent 9b2fdad56c
commit 295aeb0ed8
3 changed files with 18 additions and 1 deletions

View File

@@ -940,6 +940,11 @@ static int Multiply(void)
}
if (v1.type == INT_TYPE && v2.type == INT_TYPE) {
/* Prevent floating-point exception */
if ((v2.v.val == -1 && v1.v.val == INT_MIN) ||
(v1.v.val == -1 && v2.v.val == INT_MIN)) {
return E_2HIGH;
}
int old = v1.v.val;
v1.v.val *= v2.v.val;
if (v2.v.val != 0) {

View File

@@ -3117,10 +3117,20 @@ $IntMin => -2147483648
- 1 => -1
-2147483648 / -1 => Number too high
../tests/test.rem(553): `/': Number too high
set a $IntMin * (-1)
$IntMin => -2147483648
- 1 => -1
-2147483648 * -1 => Number too high
../tests/test.rem(554): `*': Number too high
set a (-1) * $IntMin
- 1 => -1
$IntMin => -2147483648
-1 * -2147483648 => Number too high
../tests/test.rem(555): `*': Number too high
set a abs($IntMin)
$IntMin => -2147483648
abs(-2147483648) => Number too high
../tests/test.rem(554): Number too high
../tests/test.rem(556): Number too high
# Don't want Remind to queue reminders
EXIT

View File

@@ -551,6 +551,8 @@ set a $IntMin * 2
set a $IntMin * $IntMin
set a $IntMin * $IntMax
set a $IntMin / (-1)
set a $IntMin * (-1)
set a (-1) * $IntMin
set a abs($IntMin)
# Don't want Remind to queue reminders