From 50e5bba9dfdb060cf8f6cf139cb630854ba0c6ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Tue, 29 Nov 2022 20:47:26 +0100 Subject: [PATCH] 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. --- main/gbx/gb_error.c | 5 +++++ main/gbx/gb_error.h | 1 + main/gbx/gbx_exec_loop.c | 16 ++++++++-------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/main/gbx/gb_error.c b/main/gbx/gb_error.c index 996dfba21..38e2753bc 100644 --- a/main/gbx/gb_error.c +++ b/main/gbx/gb_error.c @@ -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, ...) { diff --git a/main/gbx/gb_error.h b/main/gbx/gb_error.h index 9ccd05e99..343f3a4f4 100644 --- a/main/gbx/gb_error.h +++ b/main/gbx/gb_error.h @@ -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; diff --git a/main/gbx/gbx_exec_loop.c b/main/gbx/gbx_exec_loop.c index f9f39e813..2f226bfdc 100644 --- a/main/gbx/gbx_exec_loop.c +++ b/main/gbx/gbx_exec_loop.c @@ -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: