Finally the divide operator does not return infinities. It raises a "Mathematic error" instead.

[INTERPRETER]
* NEW: Finally the divide operator does not return infinities. It raises a "Mathematic error" instead.
This commit is contained in:
Benoît Minisini 2022-11-29 20:47:26 +01:00
parent c997255367
commit 50e5bba9df
3 changed files with 14 additions and 8 deletions

View File

@ -577,6 +577,11 @@ void THROW_SYSTEM(int err, const char *path)
}
}
void THROW_MATH(bool zero)
{
THROW(zero ? E_ZERO : E_MATH);
}
void ERROR_fatal(const char *error, ...)
{

View File

@ -167,6 +167,7 @@ void THROW_ILLEGAL(void) NORETURN;
void THROW_STACK(void) NORETURN;
void THROW_BOUND(void) NORETURN;
void THROW_CLASS(void *class, char *arg1, char *arg2) NORETURN;
void THROW_MATH(bool zero) NORETURN;
void ERROR_fatal(const char *error, ...) NORETURN;
void ERROR_panic(const char *error, ...) NORETURN;

View File

@ -2187,16 +2187,16 @@ _DIV_INTEGER:
VALUE_conv_float(&SP[-1]);
VALUE_conv_float(SP);
SP[-1]._float.value /= SP->_float.value;
if (!isfinite(SP[-1]._float.value) && SP->_float.value == 0)
THROW(E_ZERO);
if (!isfinite(SP[-1]._float.value))
THROW_MATH(SP->_float.value == 0);
goto _NEXT;
_DIV_FLOAT:
SP--;
SP[-1]._float.value /= SP->_float.value;
if (!isfinite(SP[-1]._float.value) && SP->_float.value == 0)
THROW(E_ZERO);
if (!isfinite(SP[-1]._float.value))
THROW_MATH(SP->_float.value == 0);
goto _NEXT;
/*-----------------------------------------------*/
@ -3473,13 +3473,13 @@ __FLOAT:
__FLOAT_NC:
P1->_float.value /= P2->_float.value;
if (isfinite(P1->_float.value) || P2->_float.value)
if (isfinite(P1->_float.value))
{
SP--;
return;
}
THROW(E_ZERO);
THROW_MATH(P2->_float.value == 0);
__SINGLE:
@ -3489,13 +3489,13 @@ __SINGLE:
__SINGLE_NC:
P1->_single.value /= P2->_single.value;
if (isfinite(P1->_single.value) || P2->_single.value)
if (isfinite(P1->_single.value))
{
SP--;
return;
}
THROW(E_ZERO);
THROW_MATH(P2->_single.value == 0);
__OBJECT_FLOAT: