src/maths/cmaths, implement `nint()' (.control language)
This commit is contained in:
parent
9e72296e40
commit
c6a8429258
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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…
Reference in New Issue