From 7df63d456eece5ec6e50a7f5b75c69dd052f48b8 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 7 Jan 2015 22:02:40 +0100 Subject: [PATCH 1/6] Remove unneeded tests for . This test is also present in FreeBSD's . For FreeBSD it makes sense, but for a portable math library, we cannot assume that the system has a header file like and that it uses a common header guard. --- amd64/bsd_ieeefp.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/amd64/bsd_ieeefp.h b/amd64/bsd_ieeefp.h index edb0d9c..8a7ee20 100644 --- a/amd64/bsd_ieeefp.h +++ b/amd64/bsd_ieeefp.h @@ -38,10 +38,6 @@ #ifndef _MACHINE_IEEEFP_H_ #define _MACHINE_IEEEFP_H_ -#if !defined(_SYS_CDEFS_H) && !defined(_SYS_CDEFS_H_) && !defined(_CDEFS_H_) -#error this file needs sys/cdefs.h as a prerequisite -#endif - /* * FP rounding modes */ From 71f60ec6321f6a3ef50d9834255ef506135d4005 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 7 Jan 2015 22:07:48 +0100 Subject: [PATCH 2/6] Prevent the use of deprecated or internal functions if possible. The finite() function has been superseded by isfinite(). There is also no need to use scalb(), as the exponent is also an integer value. We can simply use scalbn(). There is also no need to use __isnanf(). The values passed are guaranteed to be of type float, meaning we can safely use the standard isnan(). --- bsdsrc/b_exp.c | 6 +++--- bsdsrc/b_tgamma.c | 2 +- src/e_scalb.c | 2 +- src/e_scalbf.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bsdsrc/b_exp.c b/bsdsrc/b_exp.c index 61c96eb..d71c7de 100644 --- a/bsdsrc/b_exp.c +++ b/bsdsrc/b_exp.c @@ -152,13 +152,13 @@ double x, c; c= x - z*(p1+z*(p2+z*(p3+z*(p4+z*p5)))); c = (x*c)/(2.0-c); - return scalb(1.+(hi-(lo - c)), k); + return scalbn(1.+(hi-(lo - c)), k); } /* end of x > lntiny */ else /* exp(-big#) underflows to zero */ - if(finite(x)) return(scalb(1.0,-5000)); + if(isfinite(x)) return(scalbn(1.0,-5000)); /* exp(-INF) is zero */ else return(0.0); @@ -167,5 +167,5 @@ double x, c; else /* exp(INF) is INF, exp(+big#) overflows to INF */ - return( finite(x) ? scalb(1.0,5000) : x); + return( isfinite(x) ? scalbn(1.0,5000) : x); } diff --git a/bsdsrc/b_tgamma.c b/bsdsrc/b_tgamma.c index 7380b1d..a5cfb0f 100644 --- a/bsdsrc/b_tgamma.c +++ b/bsdsrc/b_tgamma.c @@ -140,7 +140,7 @@ tgamma(x) if (x != 0.0) u.a = one - tiny; /* raise inexact */ return (one/x); - } else if (!finite(x)) + } else if (!isfinite(x)) return (x - x); /* x is NaN or -Inf */ else return (neg_gam(x)); diff --git a/src/e_scalb.c b/src/e_scalb.c index d575100..e0c9165 100644 --- a/src/e_scalb.c +++ b/src/e_scalb.c @@ -35,7 +35,7 @@ __ieee754_scalb(double x, double fn) return scalbn(x,fn); #else if (isnan(x)||isnan(fn)) return x*fn; - if (!finite(fn)) { + if (!isfinite(fn)) { if(fn>0.0) return x*fn; else return x/(-fn); } diff --git a/src/e_scalbf.c b/src/e_scalbf.c index d506719..7472d37 100644 --- a/src/e_scalbf.c +++ b/src/e_scalbf.c @@ -30,8 +30,8 @@ __ieee754_scalbf(float x, float fn) #ifdef _SCALB_INT return scalbnf(x,fn); #else - if ((__isnanf)(x)||(__isnanf)(fn)) return x*fn; - if (!finitef(fn)) { + if (isnan(x)||isnan(fn)) return x*fn; + if (!isfinite(fn)) { if(fn>(float)0.0) return x*fn; else return x/(-fn); } From f835657bd8ade3b7cd7fd208824548aaeceb4ebe Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 7 Jan 2015 22:11:36 +0100 Subject: [PATCH 3/6] Remove checks against header guards. It seems that this header conditionally tests whether is included, as the 'complex' keyword is otherwise not available. This version of math_private.h includes unconditionally, so there is no need to test against this. --- src/math_private.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/math_private.h b/src/math_private.h index a8c0595..05d95c3 100644 --- a/src/math_private.h +++ b/src/math_private.h @@ -333,9 +333,7 @@ double __kernel_sin(double,double,int); double __kernel_cos(double,double); double __kernel_tan(double,double,int); double __ldexp_exp(double,int); -#ifdef _COMPLEX_H double complex __ldexp_cexp(double complex,int); -#endif /* float precision kernel functions */ #ifdef INLINE_REM_PIO2F @@ -355,9 +353,7 @@ __inline #endif float __kernel_tandf(double,int); float __ldexp_expf(float,int); -#ifdef _COMPLEX_H float complex __ldexp_cexpf(float complex,int); -#endif /* long double precision kernel functions */ long double __kernel_sinl(long double, long double, int); From f9fd21c96f3a573f14e80de74605faa5e7525a94 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 7 Jan 2015 22:20:56 +0100 Subject: [PATCH 4/6] Don't define __ISO_C_VISIBLE unconditionally. __ISO_C_VISIBLE is already defined on FreeBSD. By default, it has a value of 2011. This causes a lot of compiler warnings. --- src/openlibm.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/openlibm.h b/src/openlibm.h index 5bfd0af..5635612 100644 --- a/src/openlibm.h +++ b/src/openlibm.h @@ -57,7 +57,9 @@ extern const union __nan_un { //VBS begin #define __MATH_BUILTIN_CONSTANTS #define __MATH_BUILTIN_RELOPS +#ifndef __ISO_C_VISIBLE #define __ISO_C_VISIBLE 1999 +#endif //VBS end #ifdef __MATH_BUILTIN_CONSTANTS From 9a48c873869861582640ed12bfb8ed4ba8289dab Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 7 Jan 2015 22:22:52 +0100 Subject: [PATCH 5/6] Don't attempt to pull in directly. is not a standard header. Instead, we'd better pull in a common header like . It is very likely that such a header already provides the necessary bits. --- include/cdefs-compat.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/include/cdefs-compat.h b/include/cdefs-compat.h index 173bc91..7c997c9 100644 --- a/include/cdefs-compat.h +++ b/include/cdefs-compat.h @@ -1,9 +1,11 @@ #ifndef _CDEFS_COMPAT_H_ #define _CDEFS_COMPAT_H_ -#ifndef _WIN32 -#include "sys/cdefs.h" -#else /* _WIN32 */ +/* + * We cannot be certain that this operating system has . + * Instead, include a header file that is likely to pull in this header. + */ +#include #if defined(__cplusplus) #define __BEGIN_DECLS extern "C" { @@ -13,13 +15,6 @@ #define __END_DECLS #endif -#define _SYS_CDEFS_H_ - -#endif /* _WIN32 */ - - - - #ifdef __GNUC__ #ifndef __strong_reference #ifdef __APPLE__ From 78f622e84a2a49242a2686f10e9d0e0ce1805018 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 7 Jan 2015 22:33:54 +0100 Subject: [PATCH 6/6] Use endianness definitions provided by GCC or Clang if available. Instead of using all sorts of operating system specific constructs, we can just query the compiler which byte order is being used. This has the advantage that the code builds on new platforms without any tweaks. --- include/fpmath.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/include/fpmath.h b/include/fpmath.h index 3b06b7e..5698b96 100644 --- a/include/fpmath.h +++ b/include/fpmath.h @@ -38,28 +38,37 @@ #endif #endif -#ifdef __linux +#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) + +/* Definitions provided directly by GCC and Clang. */ +#define _LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +#define _BIG_ENDIAN __ORDER_BIG_ENDIAN__ +#define _PDP_ENDIAN __ORDER_PDP_ENDIAN__ +#define _BYTE_ORDER __BYTE_ORDER__ + +#elif defined(__linux) + #include #include #define _LITTLE_ENDIAN __LITTLE_ENDIAN #define _BIG_ENDIAN __BIG_ENDIAN #define _PDP_ENDIAN __PDP_ENDIAN #define _BYTE_ORDER __BYTE_ORDER -#endif -#ifdef __APPLE__ +#elif defined(__APPLE__) + #include #define _LITTLE_ENDIAN LITTLE_ENDIAN #define _BIG_ENDIAN BIG_ENDIAN #define _PDP_ENDIAN PDP_ENDIAN #define _BYTE_ORDER BYTE_ORDER -#endif -#ifdef __FreeBSD__ +#elif defined(__FreeBSD__) + #include -#endif -#ifdef _WIN32 +#elif defined(_WIN32) + #define _LITTLE_ENDIAN 1234 #define _BIG_ENDIAN 4321 #define _PDP_ENDIAN 3412 @@ -69,6 +78,7 @@ #define BIG_ENDIAN _BIG_ENDIAN #define PDP_ENDIAN _PDP_ENDIAN #define BYTE_ORDER _BYTE_ORDER + #endif #ifndef _IEEE_WORD_ORDER