From 07bb8091582fb0c341c81d1782d79928b5484d7c Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 30 Aug 2022 20:02:46 +0200 Subject: [PATCH] Iterations for op or dc may start with arguments 0 for ln(). To cope with this, and potential overflow in exp function, some limits have been added. --- src/spicelib/parser/ptfuncs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/spicelib/parser/ptfuncs.c b/src/spicelib/parser/ptfuncs.c index 845f8b46a..9410a81fd 100644 --- a/src/spicelib/parser/ptfuncs.c +++ b/src/spicelib/parser/ptfuncs.c @@ -216,21 +216,29 @@ PTcosh(double arg) } /* Limit the exp: If arg > EXPARGMAX (arbitrarily selected to 14), continue with linear output, - if compatmode PSPICE is selected*/ + if compatmode PSPICE is selected. + If arg exceeds 227.9559242, output its exp value 1e99. */ double PTexp(double arg) { if (newcompat.ps && arg > EXPARGMAX) return EXPMAX * (arg - EXPARGMAX + 1.); + else if (arg > 227.9559242) + return 1e99; else return (exp(arg)); } +/* If arg < , returning HUGE will lead to an error message. + If arg == 0, don't bail out, but return an arbitrarily very negative value (-1e99). + Arg 0 may happen, when starting iteration for op or dc simulation. */ double PTlog(double arg) { if (arg < 0.0) return (HUGE); + if (arg == 0) + return -1e99; return (log(arg)); } @@ -239,6 +247,8 @@ PTlog10(double arg) { if (arg < 0.0) return (HUGE); + if (arg == 0) + return -1e99; return (log10(arg)); }