Browse Source

Add new functions for operators x**y or x^y

compatmode hs: x>0 pow(x, y), x<0 pow(x, round(y)), X=0 0
compatmode lt: x>0 pow(x, y), x<0 pow(x, y) if y is close to integer, else 0
pre-master-46
Holger Vogt 3 years ago
parent
commit
d0f686727d
  1. 26
      src/frontend/numparam/xpressn.c

26
src/frontend/numparam/xpressn.c

@ -773,7 +773,31 @@ operate(char op, double x, double y)
x = x / y; x = x / y;
break; break;
case '^': /* power */ case '^': /* power */
x = pow(fabs(x), y);
if (newcompat.hs) {
if (x < 0)
x = pow(x, round(y));
else if (x == 0)
x = 0;
else
x = pow(x, y);
}
else if (newcompat.lt) {
if (x >= 0)
x = pow(x, y);
else {
/* If arg2 is quasi an integer, round it to have pow not fail
when arg1 is negative. Takes into account the double
representation which sometimes differs in the last digit(s). */
if (AlmostEqualUlps(nearbyint(y), y, 10))
x = pow(x, round(y));
else
/* As per LTSPICE specification for ** */
x = 0;
}
}
else {
x = pow(fabs(x), y);
}
break; break;
case 'A': /* && */ case 'A': /* && */
x = ((x != 0.0) && (y != 0.0)) ? 1.0 : 0.0; x = ((x != 0.0) && (y != 0.0)) ? 1.0 : 0.0;

Loading…
Cancel
Save