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

This commit is contained in:
rlar 2015-05-02 12:27:35 +02:00
parent 44425b1d0a
commit e609c7411d
3 changed files with 31 additions and 18 deletions

View File

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

View File

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

View File

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