From 8ad6bd209dea7b13cb0182b3e655ed45450b59fb Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 7 Dec 2013 12:14:47 +0100 Subject: [PATCH] replacements for functions missing in the msvc world --- src/frontend/numparam/xpressn.c | 20 ---------------- src/include/ngspice/ngspice.h | 8 +++++++ visualc-shared/sharedspice.vcproj | 4 ++++ visualc/msvc-compat.c | 39 +++++++++++++++++++++++++++++++ visualc/vngspice.vcproj | 4 ++++ 5 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 visualc/msvc-compat.c diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index 58a0875a8..6480996f2 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -177,33 +177,13 @@ mathfunction(int f, double z, double x) y = atan(x); break; case XFU_ASINH: -#ifdef HAVE_ASINH y = asinh(x); -#else - y = ((x > 0) ? log(x + sqrt(x * x + 1.0)) : -log(-x + sqrt(x * x + 1.0))); -#endif break; case XFU_ACOSH: -#ifdef HAVE_ACOSH y = acosh(x); -#else - /* domain check (HUGE_VAL like gnu libc) */ - if (x < 1.) - y = HUGE_VAL; - else - y = (log(x + sqrt(x*x-1.0))); -#endif break; case XFU_ATANH: -#ifdef HAVE_ATANH y = atanh(x); -#else - /* domain check (HUGE_VAL like gnu libc) */ - if (fabs(x) >= 1.) - y = HUGE_VAL; - else - y = (log((1.0 + x) / (1.0 - x)) / 2.0); -#endif break; case XFU_TAN: y = tan(x); diff --git a/src/include/ngspice/ngspice.h b/src/include/ngspice/ngspice.h index bc51e0860..7ff9b99ee 100644 --- a/src/include/ngspice/ngspice.h +++ b/src/include/ngspice/ngspice.h @@ -158,6 +158,14 @@ extern void SetAnalyse(char *Analyse, int Percent); #if defined (_MSC_VER) #include #include +#define trunc x_trunc +extern double x_trunc(double); +#define asinh x_asinh +extern double x_asinh(double); +#define acosh x_acosh +extern double x_acosh(double); +#define atanh x_atanh +extern double x_atanh(double); #define strdup _strdup #define unlink _unlink #define fileno _fileno diff --git a/visualc-shared/sharedspice.vcproj b/visualc-shared/sharedspice.vcproj index 95442db6c..7f08768f5 100644 --- a/visualc-shared/sharedspice.vcproj +++ b/visualc-shared/sharedspice.vcproj @@ -6444,6 +6444,10 @@ RelativePath="..\src\spicelib\devices\mos9\mos9trun.c" > + + diff --git a/visualc/msvc-compat.c b/visualc/msvc-compat.c new file mode 100644 index 000000000..a68754f3c --- /dev/null +++ b/visualc/msvc-compat.c @@ -0,0 +1,39 @@ +#include + +/* + * some rather simple minded replacements + * for functions missing in most msvc incarnations + */ + +double +x_trunc(double x) +{ + return (x < 0) ? ceil(x) : floor(x); +} + + +double +x_asinh(double x) +{ + return (x > 0) ? log(x + sqrt(x * x + 1.0)) : -log(-x + sqrt(x * x + 1.0)); +} + +double +x_acosh(double x) +{ + /* domain check (HUGE_VAL like gnu libc) */ + if (x < 1.0) + return HUGE_VAL; + else + return log(x + sqrt(x * x - 1.0)); +} + +double +x_atanh(double x) +{ + /* domain check (HUGE_VAL like gnu libc) */ + if (fabs(x) >= 1.0) + return HUGE_VAL; + else + return log((1.0 + x) / (1.0 - x)) / 2.0; +} diff --git a/visualc/vngspice.vcproj b/visualc/vngspice.vcproj index 92e1638e6..9ecf12632 100644 --- a/visualc/vngspice.vcproj +++ b/visualc/vngspice.vcproj @@ -7268,6 +7268,10 @@ RelativePath="..\src\spicelib\devices\mos9\mos9trun.c" > + +