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

This commit is contained in:
rlar 2014-09-20 14:09:11 +02:00
parent 9e72296e40
commit c6a8429258
4 changed files with 32 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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