Browse Source

derivatives for min, max

pre-master-46
h_vogt 16 years ago
parent
commit
7be4dc785e
  1. 1
      ChangeLog
  2. 47
      src/spicelib/parser/inpptree.c

1
ChangeLog

@ -1,6 +1,7 @@
2010-05-09 Holger Vogt
* inpcom.c: patch 09/05/10 by Robert
* spinit.in: add ngbehavior
* inpptree.c: derivatives for fcns min and max
2010-05-08 Holger Vogt
* inpcom.c: patch 02/05/10 by Robert: avoid subtraction from a builtin 1.0

47
src/spicelib/parser/inpptree.c

@ -2,7 +2,7 @@
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1987 Wayne A. Christopher, U. C. Berkeley CAD Group
**********/
/*#define TRACE*/
//#define TRACE
#include "ngspice.h"
#include "ifsim.h"
@ -441,17 +441,42 @@ static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum)
arg1 = mkcon((double) 0.0);
break;
case PTF_MIN:
/*
min(a,b)
p->left: ',' p->left->left: a p->left->right: b
*/
newp = mkcon((double) 0);
return (newp);
case PTF_MIN:
case PTF_MAX:
/* min(a,b) --> (a<b) ? a : b
* --> ((a-b) < 0) ? a : b
*/
{
INPparseNode *a = p->left->left;
INPparseNode *b = p->left->right;
int comparison = (p->funcnum == PTF_MIN) ? PTF_LT0 : PTF_GT0;
#ifdef TRACE
extern void printTree(INPparseNode *);
printf("debug: %s, PTF_MIN: ", __func__);
printTree(p);
printf("\n");
printf("debug: %s, PTF_MIN, a: ", __func__);
printTree(a);
printf("\n");
printf("debug: %s, PTF_MIN, b: ", __func__);
printTree(b);
printf("\n");
#endif
newp = mkb(PT_TERN,
mkf(comparison, mkb(PT_MINUS, a, b)),
mkb(PT_COMMA,
PTdifferentiate(a, varnum),
PTdifferentiate(b, varnum)));
#ifdef TRACE
printf("debug, %s, returns; ", __func__);
printTree(newp);
printf("\n");
#endif
return (newp);
}
case PTF_MAX:
newp = mkcon((double) 0);
return (newp);
break;
case PTF_POW:
{

Loading…
Cancel
Save