Browse Source

src/frontend/vectors.c, abstraction, introduce `vec_iszero()'

pre-master-46
rlar 11 years ago
parent
commit
e609c7411d
  1. 21
      src/frontend/cpitf.c
  2. 27
      src/frontend/vectors.c
  3. 1
      src/include/ngspice/fteext.h

21
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;
}

27
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.
*/

1
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);

Loading…
Cancel
Save