From e2cf397b6d28db7ce24e7bc3733976e48718d988 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 9 Apr 2021 10:56:04 +0200 Subject: [PATCH] Restrict the limit for exp function (linear growth when exponent is larger than 14, commit [93a76d]) to the PSPICE compatibility mode. --- src/spicelib/parser/inpptree.c | 16 +++++++++++----- src/spicelib/parser/ptfuncs.c | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/spicelib/parser/inpptree.c b/src/spicelib/parser/inpptree.c index 29c0f9240..3b4c7733c 100644 --- a/src/spicelib/parser/inpptree.c +++ b/src/spicelib/parser/inpptree.c @@ -5,6 +5,7 @@ Author: 1987 Wayne A. Christopher, U. C. Berkeley CAD Group //#define TRACE #include "ngspice/ngspice.h" +#include "ngspice/compatmode.h" #include "ngspice/ifsim.h" #include "ngspice/iferrmsg.h" #include "ngspice/inpdefs.h" @@ -448,11 +449,16 @@ static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum) break; case PTF_EXP: /* u > EXPARGMAX -> EXPMAX, that is exp(EXPARGMAX), else exp(u) */ - arg1 = mkb(PT_TERN, - mkf(PTF_GT0, mkb(PT_MINUS, p->left, mkcon(EXPARGMAX))), - mkb(PT_COMMA, - mkcon(EXPMAX), - mkf(PTF_EXP, p->left))); + if (newcompat.ps) { + arg1 = mkb(PT_TERN, + mkf(PTF_GT0, mkb(PT_MINUS, p->left, mkcon(EXPARGMAX))), + mkb(PT_COMMA, + mkcon(EXPMAX), + mkf(PTF_EXP, p->left))); + } + else { /* exp(u) */ + arg1 = mkf(PTF_EXP, p->left); + } #ifdef TRACE1 printf("debug exp, %s, returns; ", __func__); diff --git a/src/spicelib/parser/ptfuncs.c b/src/spicelib/parser/ptfuncs.c index 4c376daa5..845f8b46a 100644 --- a/src/spicelib/parser/ptfuncs.c +++ b/src/spicelib/parser/ptfuncs.c @@ -215,11 +215,12 @@ PTcosh(double arg) return (cosh(arg)); } -/* Limit the exp: If arg > EXPARGMAX (arbitrarily selected to 14), continue with linear output */ +/* Limit the exp: If arg > EXPARGMAX (arbitrarily selected to 14), continue with linear output, + if compatmode PSPICE is selected*/ double PTexp(double arg) { - if (arg > EXPARGMAX) + if (newcompat.ps && arg > EXPARGMAX) return EXPMAX * (arg - EXPARGMAX + 1.); else return (exp(arg));