Skip to content

Commit

Permalink
Merge pull request #1 from OpenSEMBA/feature/modulo_step
Browse files Browse the repository at this point in the history
Feature/modulo step
  • Loading branch information
Alberto-o authored Jun 28, 2024
2 parents 03ec21c + b5d3be5 commit 7a8d344
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/frontend/breakp.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void printcond(struct dbcomm *d, FILE *fp);
static int howmanysteps = 0;
static int steps = 0;
static bool interpolated = FALSE;

static double last_rem = 0;

/* Set a breakpoint. Possible commands are:
* stop after n
Expand Down Expand Up @@ -86,6 +86,7 @@ com_stop(wordlist *wl)
d->db_iteration = i;
wl = wl->wl_next->wl_next;
} else if (eq(wl->wl_word, "when") && wl->wl_next) {

/* cp_lexer(string) will not discriminate '=', so we have
to do it here */
if (strchr(wl->wl_next->wl_word, '=') &&
Expand Down Expand Up @@ -126,11 +127,13 @@ com_stop(wordlist *wl)
wl = wl->wl_next;

/* Now get the condition */
if (eq(wl->wl_word, "eq") || eq(wl->wl_word, "="))
if (eq(wl->wl_word, "eq") || eq(wl->wl_word, "=")){
d->db_op = DBC_EQU;
else if (eq(wl->wl_word, "ne"))
} else if (eq(wl->wl_word, "ne"))
d->db_op = DBC_NEQ;
else if (eq(wl->wl_word, "gt") || eq(wl->wl_word, ">"))
else if (eq(wl->wl_word, "mod")) {
d->db_op = DBC_MOD;
} else if (eq(wl->wl_word, "gt") || eq(wl->wl_word, ">"))
d->db_op = DBC_GT;
else if (eq(wl->wl_word, "lt"))
d->db_op = DBC_LT;
Expand Down Expand Up @@ -575,6 +578,20 @@ satisfied(struct dbcomm *d, struct plot *plot)
return hit;
}
// return ((d1 == d2) ? TRUE : FALSE);
case DBC_MOD:
{
bool zero = AlmostEqualUlps(d1, 0, 3) ? TRUE : FALSE;
if (zero == TRUE)
return FALSE;
double rem = fmod(d1,d2);
bool rem_hit = FALSE;
if (rem-last_rem < 0){
rem_hit = TRUE;
}
last_rem = rem;
return rem_hit;
}

case DBC_NEQ:
return ((d1 != d2) ? TRUE : FALSE);
case DBC_GTE:
Expand Down Expand Up @@ -624,6 +641,9 @@ printcond(struct dbcomm *d, FILE *fp)
case DBC_EQU:
fputs(" =", fp);
break;
case DBC_MOD:
fputs(" mod", fp);
break;
case DBC_NEQ:
fputs(" <>", fp);
break;
Expand Down
1 change: 1 addition & 0 deletions src/include/ngspice/ftedebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
#define DBC_LT 4 /* < (lt) */
#define DBC_GTE 5 /* >= (ge) */
#define DBC_LTE 6 /* <= (le) */
#define DBC_MOD 7 /* fmod (mod) */

/* Below, members db_op and db_value1 are re-purposed by iplot options. */

Expand Down

0 comments on commit 7a8d344

Please sign in to comment.