diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/erl_interface/configure.in | 12 | ||||
-rw-r--r-- | lib/erl_interface/src/encode/encode_double.c | 12 | ||||
-rw-r--r-- | lib/erl_interface/src/legacy/erl_eterm.c | 10 |
3 files changed, 34 insertions, 0 deletions
diff --git a/lib/erl_interface/configure.in b/lib/erl_interface/configure.in index ef78f0f87b..076170c648 100644 --- a/lib/erl_interface/configure.in +++ b/lib/erl_interface/configure.in @@ -139,6 +139,18 @@ esac AC_CHECK_LIB([nsl], [gethostbyname]) AC_CHECK_LIB([socket], [getpeername]) +AC_MSG_CHECKING([for isfinite]) +AC_TRY_LINK([#include <math.h>], + [isfinite(0);], have_isfinite=yes, have_isfinite=no), + +if test $have_isfinite = yes; then + AC_DEFINE(HAVE_ISFINITE,[1], + [Define to 1 if you have the `isfinite' function.]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + # Checks for header files. AC_HEADER_STDC AC_HEADER_SYS_WAIT diff --git a/lib/erl_interface/src/encode/encode_double.c b/lib/erl_interface/src/encode/encode_double.c index 148a49f73a..a19a871eda 100644 --- a/lib/erl_interface/src/encode/encode_double.c +++ b/lib/erl_interface/src/encode/encode_double.c @@ -18,6 +18,9 @@ */ #include <stdio.h> #include <string.h> +#if defined(HAVE_ISFINITE) +#include <math.h> +#endif #include "eidef.h" #include "eiext.h" #include "putget.h" @@ -27,6 +30,15 @@ int ei_encode_double(char *buf, int *index, double p) char *s = buf + *index; char *s0 = s; + /* Erlang does not handle Inf and NaN, so we return an error rather + * than letting the Erlang VM complain about a bad external + * term. */ +#if defined(HAVE_ISFINITE) + if(!isfinite(p)) { + return -1; + } +#endif + if (!buf) s += 9; else { diff --git a/lib/erl_interface/src/legacy/erl_eterm.c b/lib/erl_interface/src/legacy/erl_eterm.c index 636d26b24b..c167fd1f78 100644 --- a/lib/erl_interface/src/legacy/erl_eterm.c +++ b/lib/erl_interface/src/legacy/erl_eterm.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> #include <ctype.h> +#include <math.h> #include "ei_locking.h" #include "ei_resolve.h" @@ -125,6 +126,15 @@ ETERM *erl_mk_float (double d) { ETERM *ep; + /* Erlang does not handle Inf and NaN, so we return an error + * rather than letting the Erlang VM complain about a bad external + * term. */ + switch(fpclassify(d)) { + case FP_NAN: + case FP_INFINITE: + return NULL; + } + ep = erl_alloc_eterm(ERL_FLOAT); ERL_COUNT(ep) = 1; ERL_FLOAT_VALUE(ep) = d; |