Browse Source

floor(), ceil() added

h_vogt 14 years ago
parent
commit
75767fcc3d
  1. 6
      ChangeLog
  2. 10
      src/frontend/numparam/xpressn.c
  3. 2
      src/frontend/parse.c
  4. 2
      src/include/ngspice/fteext.h
  5. 2
      src/include/ngspice/inpptree.h
  6. 58
      src/maths/cmaths/cmath2.c
  7. 4
      src/maths/cmaths/cmath2.h
  8. 3
      src/spicelib/parser/inp.h
  9. 11
      src/spicelib/parser/inpptree.c
  10. 13
      src/spicelib/parser/ptfuncs.c

6
ChangeLog

@ -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 2011-12-25 Holger Vogt
* src/frontend/inpcom.c : remove 'params:' from X or .SUBCKT lines * src/frontend/inpcom.c : remove 'params:' from X or .SUBCKT lines
of input deck (in fcn inp_fix_for_numparam()) of input deck (in fcn inp_fix_for_numparam())

10
src/frontend/numparam/xpressn.c

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

2
src/frontend/parse.c

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

2
src/include/ngspice/fteext.h

@ -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_tan(void *, short int , int , int *, short int *);
extern void *cx_tanh(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_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 */ /* cmath2.c */

2
src/include/ngspice/inpptree.h

@ -122,6 +122,8 @@ typedef struct INPparseNode {
#define PTF_POW 30 #define PTF_POW 30
#define PTF_MIN 31 #define PTF_MIN 31
#define PTF_MAX 32 #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 /* The following things are used by the parser -- these are the token types the
* lexer returns. * lexer returns.

58
src/maths/cmaths/cmath2.c

@ -786,3 +786,61 @@ cx_d(void *data, short int type, int length, int *newlength, short int *newtype)
return ((void *) c); 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);
}
}

4
src/maths/cmaths/cmath2.h

@ -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_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_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_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 #endif

3
src/spicelib/parser/inp.h

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

11
src/spicelib/parser/inpptree.c

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

13
src/spicelib/parser/ptfuncs.c

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