From 1b28b829eb10fddc2aa649e334d2c829c82a76cc Mon Sep 17 00:00:00 2001
From: Marcus Comstedt <marcus@mc.pp.se>
Date: Mon, 28 May 2001 20:15:07 +0200
Subject: [PATCH] Added two methods for generating NaN, infnan() (BSD 4.3) and
 nan() (C99).

Rev: src/acconfig.h:1.86
Rev: src/configure.in:1.521
Rev: src/opcodes.c:1.108
---
 src/acconfig.h   |  5 ++++-
 src/configure.in | 14 +++++++++++++-
 src/opcodes.c    | 21 ++++++++++++++++-----
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/src/acconfig.h b/src/acconfig.h
index 96d45b68a1..bc394581eb 100644
--- a/src/acconfig.h
+++ b/src/acconfig.h
@@ -1,5 +1,5 @@
 /*
- * $Id: acconfig.h,v 1.85 2001/05/27 16:58:57 grubba Exp $
+ * $Id: acconfig.h,v 1.86 2001/05/28 18:15:06 marcus Exp $
  */
 #ifndef MACHINE_H
 #define MACHINE_H
@@ -156,6 +156,9 @@
 /* So has True64, but no useful information in prstatus_t */
 #undef GETRUSAGE_THROUGH_PROCFS_PRS
 
+/* Define if you have infnan */
+#undef HAVE_INFNAN
+
 /* Define if you have fork */
 #undef HAVE_FORK
 
diff --git a/src/configure.in b/src/configure.in
index 036bfe1c53..4bb4d8bf33 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.520 2001/05/27 16:58:58 grubba Exp $")
+AC_REVISION("$Id: configure.in,v 1.521 2001/05/28 18:15:06 marcus Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -2523,6 +2523,7 @@ AC_CHECK_FUNCS( \
  iszero \
  finite \
  signbit \
+ nan \
  nice \
  __priocntl \
  sched_setscheduler \
@@ -2668,6 +2669,17 @@ if test $ac_cv_func_crypt$ac_cv_func__crypt = nono ; then
 fi
 
 
+#############################################################################
+MY_CHECK_FUNCTION(infnan,
+[
+#include <errno.h>
+#include <math.h>
+], [
+  double pinf = infnan(ERANGE);
+  double ninf = infnan(-ERANGE);
+  double nan = infnan(EDOM);
+  exit(!(isinf(pinf)>0 && isinf(ninf)<0 && isnan(nan)));
+])
 #############################################################################
 
 # FreeBSD 3.0 has broken F_SETFD when running with threads.
diff --git a/src/opcodes.c b/src/opcodes.c
index f18ccc4a59..38be41398e 100644
--- a/src/opcodes.c
+++ b/src/opcodes.c
@@ -5,6 +5,7 @@
 \*/
 /**/
 #include "global.h"
+#include <errno.h>
 #include <math.h>
 #include <ctype.h>
 #include "interpret.h"
@@ -26,7 +27,7 @@
 #include "bignum.h"
 #include "operators.h"
 
-RCSID("$Id: opcodes.c,v 1.107 2001/05/15 04:33:58 hubbe Exp $");
+RCSID("$Id: opcodes.c,v 1.108 2001/05/28 18:15:07 marcus Exp $");
 
 void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind)
 {
@@ -881,12 +882,21 @@ static INLINE FLOAT_TYPE low_parse_IEEE_float(char *b, int sz)
   if(e>=9999)
     if(f||extra_f) {
       /* NAN */
-      
-      /* Hmm...  No idea how to generate NaN in a portable way. */
-      /* Let's turn it into a 0 for now... */
+#ifdef HAVE_INFNAN
+      return (FLOAT_TYPE)infnan(EDOM);
+#else
+#ifdef HAVE_NAN
+      /* C99 provides a portable way of generating NaN */
+      return (FLOAT_TYPE)nan("");
+#else
       return (FLOAT_TYPE)0.0;
+#endif /* HAVE_NAN */
+#endif /* HAVE_INFNAN */
     } else {
       /* +/- Infinity */
+#ifdef HAVE_INFNAN
+      return (FLOAT_TYPE)infnan(s? -ERANGE:ERANGE);
+#else
 #ifdef HUGE_VAL
       return (FLOAT_TYPE)(s? -HUGE_VAL:HUGE_VAL);
 #else
@@ -894,7 +904,8 @@ static INLINE FLOAT_TYPE low_parse_IEEE_float(char *b, int sz)
       e = 1024;
       f = 1;
       extra_f = 0;
-#endif
+#endif /* HUGE_VAL */
+#endif /* HAVE_INFNAN */
     }
 
   r = (double)f;
-- 
GitLab