diff --git a/src/frontend/cpitf.c b/src/frontend/cpitf.c index 21c777815..28fe87906 100644 --- a/src/frontend/cpitf.c +++ b/src/frontend/cpitf.c @@ -299,9 +299,9 @@ ft_cpinit(void) bool cp_istrue(wordlist *wl) { - int i; struct dvec *v; struct pnode *names; + bool rv; /* First do all the csh-type stuff here... */ wl = wl_copy(wl); @@ -314,24 +314,9 @@ cp_istrue(wordlist *wl) v = ft_evaluate(names); - for (; v; v = v->v_link2) - if (isreal(v)) { - for (i = 0; i < v->v_length; i++) - if (v->v_realdata[i] != 0.0) { - free_pnode(names); - return (TRUE); - } - } else { - for (i = 0; i < v->v_length; i++) - if ((realpart(v->v_compdata[i]) != 0.0) || - (imagpart(v->v_compdata[i]) != 0.0)) { - free_pnode(names); - return (TRUE); - } - } - + rv = !vec_iszero(v); free_pnode(names); - return (FALSE); + return rv; } diff --git a/src/frontend/vectors.c b/src/frontend/vectors.c index 78fb97a4b..70c02ef46 100644 --- a/src/frontend/vectors.c +++ b/src/frontend/vectors.c @@ -883,6 +883,33 @@ vec_free_x(struct dvec *v) } +/* + * return TRUE if every vector element is zero + */ + +bool +vec_iszero(struct dvec *v) +{ + int i; + + for (; v; v = v->v_link2) + if (isreal(v)) + for (i = 0; i < v->v_length; i++) { + if (v->v_realdata[i] != 0.0) + return FALSE; + } + else + for (i = 0; i < v->v_length; i++) { + if (realpart(v->v_compdata[i]) != 0.0) + return FALSE; + if (imagpart(v->v_compdata[i]) != 0.0) + return FALSE; + } + + return TRUE; +} + + /* This is something we do in a few places... Since vectors get copied a lot, * we can't just compare pointers to tell if two vectors are 'really' the same. */ diff --git a/src/include/ngspice/fteext.h b/src/include/ngspice/fteext.h index 85fc2bd18..059554c48 100644 --- a/src/include/ngspice/fteext.h +++ b/src/include/ngspice/fteext.h @@ -323,6 +323,7 @@ extern int ft_typnum(char *); /* vectors.c */ +extern bool vec_iszero(struct dvec *v); extern bool vec_eq(struct dvec *v1, struct dvec *v2); extern int plot_num; extern struct dvec *vec_fromplot(char *word, struct plot *plot);