From 9ab6d950a4cc836672b9100968a5b9f0ee738994 Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Wed, 11 Dec 2019 16:03:44 +0000
Subject: [PATCH] add a hack to handle the OSX case where ieee754.h is missing

---
 meson.build                 | 10 ++++++++++
 src/binary_c_code_options.h |  2 ++
 src/maths/binary_c_drandr.c |  6 ++++++
 3 files changed, 18 insertions(+)

diff --git a/meson.build b/meson.build
index fce95952b..4b9685398 100644
--- a/meson.build
+++ b/meson.build
@@ -559,6 +559,16 @@ if compiler.has_header('malloc.h',
     cflags += '-D__HAVE_MALLOC_H__'
 endif
 
+############
+# malloc.h #
+#
+if compiler.has_header('ieee754.h',
+                       args: cflags,
+                       include_directories: include_directories(incdirs))
+    cflags += '-D__HAVE_IEEE754_H__'
+endif
+
+
 ############ 
 # setitimer 
 #
diff --git a/src/binary_c_code_options.h b/src/binary_c_code_options.h
index 98a66eb3d..7e0569410 100644
--- a/src/binary_c_code_options.h
+++ b/src/binary_c_code_options.h
@@ -919,8 +919,10 @@ void Print_trace(void);
  * use snprintf in place of strlcpy 
  */
 #ifndef __HAVE_LIBBSD__
+#undef strlcpy
 #define strlcpy(d,s,n) snprintf((d),(n),"%s",(s))
 #define __STRLCPY_IS_MACRO__
+#undef strlcat
 #define strlcat(dest,source,size) __local_bsd_strlcat((dest),(source),(size))
 #define __STRLCAT_IS_BSD_COPY__
 #endif // __HAVE_LIBBSD__
diff --git a/src/maths/binary_c_drandr.c b/src/maths/binary_c_drandr.c
index b683f03c3..21307db03 100644
--- a/src/maths/binary_c_drandr.c
+++ b/src/maths/binary_c_drandr.c
@@ -35,7 +35,9 @@
 #include <stdlib.h>
 #include "binary_c_drandr_types.h"
 #include "binary_c_drandr_prototypes.h"
+#ifdef __HAVE_IEEE754_H__
 #include <ieee754.h>
+#endif // ___HAVE_IEEE754_H__
 #include <limits.h>
 #include <stdint.h>
 #include <sys/types.h>
@@ -64,7 +66,11 @@ int binary_c_erand48_r (unsigned short int xsubi[3],
        its fractional part so the resulting FP number is [0.0,1.0).  */
 
     temp.ieee.negative = 0;
+#ifdef __HAVE_IEEE754_H__
     temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
+#else
+    temp.ieee.exponent = 0x3ff; /* hard coded! */
+#endif
     temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
     temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);
 
-- 
GitLab