diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-07 12:38:21 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-07 16:30:34 +0200 |
commit | dcf0d1285d12684a5907fecb8aadca7bc2e5f44b (patch) | |
tree | 6e3ba586ad9aef18c9aac428b85479eb67c629ae | |
parent | c64877172c13b89f40d310e27552bb80e1ea230f (diff) |
eval: adjust results for arithmetic division by nan, infinity
Follow ECMAScript logic. Division by zero yields infinity, division by
infinity yields zero.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | eval.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1080,7 +1080,9 @@ ut_execute_arith(struct ut_state *state, uint32_t off) case T_DIV: if (d2 == 0.0) - return ut_new_double(NAN); + return ut_new_double(INFINITY); + else if (!isfinite(d2)) + return ut_new_double(0.0); return ut_new_double(d1 / d2); @@ -1101,7 +1103,7 @@ ut_execute_arith(struct ut_state *state, uint32_t off) case T_DIV: if (n2 == 0) - return ut_new_double(NAN); + return ut_new_double(INFINITY); return json_object_new_int64(n1 / n2); |