Browse Source

src/maths/cmaths, implement `nint()' (.control language)

pre-master-46
rlar 12 years ago
parent
commit
c6a8429258
  1. 1
      src/frontend/parse.c
  2. 1
      src/include/ngspice/fteext.h
  3. 29
      src/maths/cmaths/cmath2.c
  4. 1
      src/maths/cmaths/cmath2.h

1
src/frontend/parse.c

@ -170,6 +170,7 @@ struct func ft_funcs[] = {
{ "exponential", cx_exponential },
{ "sgauss", cx_sgauss },
{ "pos", cx_pos },
{ "nint", cx_nint },
{ "floor", cx_floor },
{ "ceil", cx_ceil },
{ "mean", cx_mean },

1
src/include/ngspice/fteext.h

@ -74,6 +74,7 @@ extern void *cx_tanh(void *, short int , int , int *, short int *);
extern void *cx_atan(void *, short int , int , int *, short int *);
extern void *cx_floor(void *, short int , int , int *, short int *);
extern void *cx_ceil(void *, short int , int , int *, short int *);
extern void *cx_nint(void *, short int , int , int *, short int *);
extern void *cx_sortorder(void *, short int , int , int *, short int *);
/* cmath2.c */

29
src/maths/cmaths/cmath2.c

@ -838,3 +838,32 @@ cx_ceil(void *data, short int type, int length, int *newlength, short int *newty
return ((void *) d);
}
}
void *
cx_nint(void *data, short int type, int length, int *newlength, short int *newtype)
{
*newlength = length;
if (type == VF_COMPLEX) {
ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data;
int i;
c = alloc_c(length);
*newtype = VF_COMPLEX;
for (i = 0; i < length; i++) {
realpart(c[i]) = nearbyint(realpart(cc[i]));
imagpart(c[i]) = nearbyint(imagpart(cc[i]));
}
return ((void *) c);
} else {
double *d;
double *dd = (double *) data;
int i;
d = alloc_d(length);
*newtype = VF_REAL;
for (i = 0; i < length; i++)
d[i] = nearbyint(dd[i]);
return ((void *) d);
}
}

1
src/maths/cmaths/cmath2.h

@ -29,6 +29,7 @@ void * cx_d(void *data, short int type, int length, int *newlength, short int *n
void * cx_avg(void *data, short int type, int length, int *newlength, short int *newtype);
void * cx_floor(void *data, short int type, int length, int *newlength, short int *newtype);
void * cx_ceil(void *data, short int type, int length, int *newlength, short int *newtype);
void * cx_nint(void *data, short int type, int length, int *newlength, short int *newtype);
#endif

Loading…
Cancel
Save