add a limit exp(arg) to the exp function. If arg is larger

than 14 (arbitrarily selected), continue with linear response.
This commit is contained in:
Holger Vogt 2020-04-13 11:05:03 +02:00
parent 87101cd26d
commit 93a76d8e21
3 changed files with 21 additions and 3 deletions

View File

@ -166,6 +166,10 @@ typedef struct PTelement {
#define PT_STACKSIZE 200
/* limits for exp function */
#define EXPARGMAX 14.
#define EXPMAX 1202604.284
/* And in IFeval.c */
extern int IFeval(IFparseTree *tree, double gmin, double *result, double *vals, double *derivs);

View File

@ -434,8 +434,18 @@ static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum)
arg1 = mkf(PTF_SINH, p->left);
break;
case PTF_EXP: /* exp(u) */
arg1 = mkf(PTF_EXP, p->left);
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)));
#ifdef TRACE
printf("debug, %s, returns; ", __func__);
printTree(arg1);
printf("\n");
#endif
break;
case PTF_LOG: /* 1 / u */

View File

@ -217,10 +217,14 @@ PTcosh(double arg)
return (cosh(arg));
}
/* Limit the exp: If arg > EXPARGMAX (arbitrarily selected to 14), continue with linear output */
double
PTexp(double arg)
{
return (exp(arg));
if (arg > EXPARGMAX)
return EXPMAX * (arg - EXPARGMAX + 1.);
else
return (exp(arg));
}
double