summaryrefslogtreecommitdiff
path: root/Zend/zend_portability.h
diff options
context:
space:
mode:
authorAndrea Faulds <ajf@ajf.me>2016-03-20 01:32:44 +0000
committerAndrea Faulds <ajf@ajf.me>2016-03-20 01:32:44 +0000
commit1c1e20d77160c5ccc402458effa9df56399ca5da (patch)
tree63de5ab9a5ecce58c49a13ee62ee92a2615ba445 /Zend/zend_portability.h
parentba4b2a60f932b05c929b843aaf010ac740579e2d (diff)
downloadphp-git-1c1e20d77160c5ccc402458effa9df56399ca5da.tar.gz
Deduplicate NAN/INF portability, move to Zend
Diffstat (limited to 'Zend/zend_portability.h')
-rw-r--r--Zend/zend_portability.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h
index 298dfb53fa..ff12d93269 100644
--- a/Zend/zend_portability.h
+++ b/Zend/zend_portability.h
@@ -53,6 +53,7 @@
#include <stdio.h>
#include <assert.h>
+#include <math.h>
#ifdef HAVE_UNIX_H
# include <unix.h>
@@ -420,6 +421,51 @@ char *alloca();
#undef MAX
#define MAX(a, b) (((a)>(b))?(a):(b))
#define MIN(a, b) (((a)<(b))?(a):(b))
+
+/* We always define a function, even if there's a macro or expression we could
+ * alias, so that using it in contexts where we can't make function calls
+ * won't fail to compile on some machines and not others.
+ */
+static zend_always_inline double _zend_get_inf(void) /* {{{ */
+{
+#ifdef INFINITY
+ return INFINITY;
+#elif HAVE_HUGE_VAL_INF
+ return HUGE_VAL;
+#elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha)
+# define _zend_DOUBLE_INFINITY_HIGH 0x7ff00000
+ double val = 0.0;
+ ((uint32_t*)&val)[1] = _zend_DOUBLE_INFINITY_HIGH;
+ ((uint32_t*)&val)[0] = 0;
+ return val;
+#elif HAVE_ATOF_ACCEPTS_INF
+ return atof("INF");
+#else
+ return 1.0/0.0;
+#endif
+} /* }}} */
+#define ZEND_INFINITY (_zend_get_inf())
+
+static zend_always_inline double _zend_get_nan(void) /* {{{ */
+{
+#ifdef NAN
+ return NAN;
+#elif HAVE_HUGE_VAL_NAN
+ return HUGE_VAL + -HUGE_VAL;
+#elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha)
+# define _zend_DOUBLE_QUIET_NAN_HIGH 0xfff80000
+ double val = 0.0;
+ ((uint32_t*)&val)[1] = _zend_DOUBLE_QUIET_NAN_HIGH;
+ ((uint32_t*)&val)[0] = 0;
+ return val;
+#elif HAVE_ATOF_ACCEPTS_NAN
+ return atof("NAN");
+#else
+ return 0.0/0.0;
+#endif
+} /* }}} */
+#define ZEND_NAN (_zend_get_nan())
+
#define ZEND_STRL(str) (str), (sizeof(str)-1)
#define ZEND_STRS(str) (str), (sizeof(str))
#define ZEND_NORMALIZE_BOOL(n) \