From 91f10abc65741b17a42c75b43c4a517b2372e0df Mon Sep 17 00:00:00 2001 From: dwarning Date: Mon, 5 Jan 2009 21:31:45 +0000 Subject: [PATCH] small polish regarding HAVE_DECL_XXX macros --- src/include/missing_math.h | 11 +++++------ src/maths/misc/isinf.c | 40 +++++++++++++++++--------------------- src/maths/misc/isnan.c | 28 +++++++++++++------------- 3 files changed, 37 insertions(+), 42 deletions(-) diff --git a/src/include/missing_math.h b/src/include/missing_math.h index 43d47585f..dd43bb7b9 100644 --- a/src/include/missing_math.h +++ b/src/include/missing_math.h @@ -2,7 +2,6 @@ Copyright 1999 Emmanuel Rouat **********/ - /* Decl. for missing maths functions, if any */ #ifndef MISSING_MATH_H_INCLUDED @@ -26,23 +25,23 @@ extern double scalb(double, double); extern double scalbn(double, int); #endif -#ifndef HAVE_DECL_ISNAN +#if !HAVE_DECL_ISNAN #ifndef HAVE_ISNAN extern int isnan(double); #endif #endif -#if (HAVE_DECL_ISINF < 1) +#if !HAVE_DECL_ISINF #ifndef HAVE_ISINF -#if defined(HAVE_FINITE) && ((HAVE_DECL_ISNAN < 1) || defined (HAVE_ISNAN)) +#if defined(HAVE_FINITE) && (HAVE_DECL_ISNAN || defined (HAVE_ISNAN)) #define isinf(x) (!finite(x) && !isnan(x)) #else #ifdef HAVE_IEEEFP_H - extern int isinf(double); +extern int isinf(double); #endif #endif #else /* HAVE_ISINF */ - extern int isinf(double); +extern int isinf(double); #endif /* HAVE_ISINF */ #endif /* HAVE_DECL_ISINF */ diff --git a/src/maths/misc/isinf.c b/src/maths/misc/isinf.c index bf73b4001..2bc497885 100644 --- a/src/maths/misc/isinf.c +++ b/src/maths/misc/isinf.c @@ -1,35 +1,31 @@ #include "ngspice.h" -#if (HAVE_DECL_ISINF < 1) - +#if !HAVE_DECL_ISINF #ifndef HAVE_ISINF - #ifdef HAVE_IEEEFP_H - int isinf(double x) { return !finite(x) && x==x; } +int isinf(double x) { return !finite(x) && x==x; } #else /* HAVE_IEEEFP_H */ - /* this is really ugly - but it is a emergency case */ - - static int - isinf(double x) - { - volatile double a = x; - - if (a > DBL_MAX) - return 1; - if (a < -DBL_MAX) - return -1; - return 0; - } +/* this is really ugly - but it is a emergency case */ + +static int +isinf (const double x) +{ + double y = x - x; + int s = (y != y); + + if (s && x > 0) + return +1; + else if (s && x < 0) + return -1; + else + return 0; +} #endif /* HAVE_IEEEFP_H */ - #else /* HAVE_ISINF */ - - int Dummy_Symbol_5; - +int Dummy_Symbol_5; #endif /* HAVE_ISINF */ - #endif /* HAVE_DECL_ISINF */ diff --git a/src/maths/misc/isnan.c b/src/maths/misc/isnan.c index ea6d349b4..e30ccab0d 100644 --- a/src/maths/misc/isnan.c +++ b/src/maths/misc/isnan.c @@ -1,45 +1,45 @@ #include "ngspice.h" -#if (HAVE_DECL_ISNAN < 1) +#if !HAVE_DECL_ISNAN #ifndef HAVE_ISNAN /* isnan (originally) for SOI devices in MINGW32 hvogt (dev.c) */ union ieee754_double { - double d; - - /* This is the IEEE 754 double-precision format. */ - struct - { + double d; + + /* This is the IEEE 754 double-precision format. */ + struct + { /* Together these comprise the mantissa. */ unsigned int mantissa1:32; unsigned int mantissa0:20; unsigned int exponent:11; unsigned int negative:1; - } ieee; - struct - { + } ieee; + struct + { /* Together these comprise the mantissa. */ unsigned int mantissa1:32; unsigned int mantissa0:19; unsigned int quiet_nan:1; unsigned int exponent:11; unsigned int negative:1; - } ieee_nan; + } ieee_nan; }; int isnan(double value) { union ieee754_double u; - + u.d = value; - + /* IEEE 754 NaN's have the maximum possible - exponent and a nonzero mantissa. */ + exponent and a nonzero mantissa. */ return ((u.ieee.exponent & 0x7ff) == 0x7ff && (u.ieee.mantissa0 != 0 || u.ieee.mantissa1 != 0)); - + } /*