Skip to content

Commit d761759

Browse files
committed
Parsing float needs to clear exceptions, re issue #889
1 parent 802e273 commit d761759

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/parser.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <ctype.h>
2+
#include <fenv.h>
23
#include <float.h>
34
#include <stdlib.h>
45
#include <stdio.h>
@@ -2840,6 +2841,9 @@ static bool parse_number(parser *p, const char **srcptr, bool neg)
28402841
}
28412842

28422843
set_float(&p->v, neg?-v:v);
2844+
#ifdef FE_INVALID
2845+
feclearexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
2846+
#endif
28432847
*srcptr = tmpptr;
28442848
mp_int_clear(&v2);
28452849
return true;
@@ -2860,6 +2864,9 @@ static bool parse_number(parser *p, const char **srcptr, bool neg)
28602864
}
28612865

28622866
set_float(&p->v, neg?-v:v);
2867+
#ifdef FE_INVALID
2868+
feclearexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
2869+
#endif
28632870
*srcptr = tmpptr;
28642871
mp_int_clear(&v2);
28652872
return true;
@@ -4328,6 +4335,9 @@ unsigned tokenize(parser *p, bool is_arg_processing, bool is_consing)
43284335
set_smallint(c, get_smallint(&p->v));
43294336
} else if (p->v.tag == TAG_FLOAT) {
43304337
set_float(c, get_float(&p->v));
4338+
#ifdef FE_INVALID
4339+
feclearexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
4340+
#endif
43314341
} else if (!p->is_string
43324342
&& (!p->is_quoted || is_func || p->is_op || p->is_var || p->is_consulting
43334343
|| (get_builtin(p->pl, SB_cstr(p->token), SB_strlen(p->token), 0, &found, NULL), found)

0 commit comments

Comments
 (0)