floor(), ceil() added

This commit is contained in:
h_vogt 2011-12-26 11:34:21 +00:00
parent 9bbf9bc549
commit 75767fcc3d
10 changed files with 107 additions and 4 deletions

View File

@ -1,3 +1,9 @@
2011-12-26 Holger Vogt
* xpressn.c
* ptfuncs.c, inpptree.c, inpptree.h, spicelib/parser/inp.h
* cmath2.c, cmath2.h, fteext.h, parse.c
functions floor and ceil added to numparam, ASRC and scripting language
2011-12-25 Holger Vogt
* src/frontend/inpcom.c : remove 'params:' from X or .SUBCKT lines
of input deck (in fcn inp_fix_for_numparam())

View File

@ -88,7 +88,7 @@ initkeys (void)
" include for to downto is var");
scopy_up (&fmathS,
"sqr sqrt sin cos exp ln arctan abs pow pwr max min int log sinh cosh"
" tanh ternary_fcn v agauss sgn gauss unif aunif limit");
" tanh ternary_fcn v agauss sgn gauss unif aunif limit ceil floor");
}
static double
@ -149,11 +149,17 @@ mathfunction (int f, double z, double x)
case 17:
y=sinh(x)/cosh(x);
break;
case 21:
case 21: /* sgn */
if (x>0) y=1.;
else if (x == 0) y=0.;
else y = -1.;
break;
case 26:
y=ceil(x);
break;
case 27:
y=floor(x);
break;
default:
y = x;
break;

View File

@ -170,6 +170,8 @@ struct func ft_funcs[] = {
{ "exponential", cx_exponential } ,
{ "sgauss", cx_sgauss } ,
{ "pos", cx_pos } ,
{ "floor", cx_floor } ,
{ "ceil", cx_ceil } ,
{ "mean", cx_mean } ,
{ "avg", cx_avg } , /* A.Roldan 03/06/05 incremental average new function */
{ "group_delay", (cx_function_t*) cx_group_delay } , /* A.Roldan 10/06/05 group delay new function */

View File

@ -71,6 +71,8 @@ extern void *cx_cosh(void *, short int , int , int *, short int *);
extern void *cx_tan(void *, short int , int , int *, short int *);
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 *);
/* cmath2.c */

View File

@ -122,6 +122,8 @@ typedef struct INPparseNode {
#define PTF_POW 30
#define PTF_MIN 31
#define PTF_MAX 32
#define PTF_CEIL 33
#define PTF_FLOOR 34
/* The following things are used by the parser -- these are the token types the
* lexer returns.

View File

@ -786,3 +786,61 @@ cx_d(void *data, short int type, int length, int *newlength, short int *newtype)
return ((void *) c);
}
}
void *
cx_floor(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]) = floor(realpart(&cc[i]));
imagpart(&c[i]) = floor(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] = floor(dd[i]);
return ((void *) d);
}
}
void *
cx_ceil(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]) = ceil(realpart(&cc[i]));
imagpart(&c[i]) = ceil(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] = ceil(dd[i]);
return ((void *) d);
}
}

View File

@ -26,7 +26,9 @@ void * cx_mod(void *data1, void *data2, short int datatype1, short int datatype2
void * cx_max(void *data, short int type, int length, int *newlength, short int *newtype);
void * cx_min(void *data, short int type, int length, int *newlength, short int *newtype);
void * cx_d(void *data, short int type, int length, int *newlength, short int *newtype);
void *cx_avg(void *data, short int type, int length, int *newlength, short int *newtype);
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);
#endif

View File

@ -73,6 +73,7 @@ double PTgt0(double arg);
double PTlt0(double arg);
double PTge0(double arg);
double PTle0(double arg);
double PTceil(double arg);
double PTfloor(double arg);
#endif

View File

@ -83,6 +83,8 @@ static struct func {
{ "tanh", PTF_TANH, (void(*)(void)) PTtanh } ,
{ "u", PTF_USTEP, (void(*)(void)) PTustep } ,
{ "uramp", PTF_URAMP, (void(*)(void)) PTuramp } ,
{ "ceil", PTF_CEIL, (void(*)(void)) PTceil } ,
{ "floor", PTF_FLOOR, (void(*)(void)) PTfloor } ,
{ "-", PTF_UMINUS, (void(*)(void)) PTuminus },
/* MW. cif function added */
{ "u2", PTF_USTEP2, (void(*)(void)) PTustep2},
@ -402,6 +404,15 @@ static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum)
arg1 = mkf(PTF_USTEP, p->left);
break;
case PTF_FLOOR: /* floor(u) */
arg1 = mkf(PTF_FLOOR, p->left);
break;
case PTF_CEIL: /* ceil(u) */
arg1 = mkf(PTF_CEIL, p->left);
break;
/* MW. PTF_CIF for new cif function */
case PTF_USTEP2: /* ustep2=uramp(x)-uramp(x-1) ustep2'=ustep(x)-ustep(x-1) */
arg1 = mkb(PT_MINUS,

View File

@ -340,3 +340,16 @@ PTpwl_derivative(double arg, void *data)
return y;
}
double
PTceil(double arg1)
{
return (ceil(arg1));
}
double
PTfloor(double arg1)
{
return (floor(arg1));
}