src/spicelib/parse, implement `nint()' (`B' language)

This commit is contained in:
rlar 2014-09-20 12:42:36 +02:00
parent 2602a492b2
commit 9e72296e40
4 changed files with 16 additions and 0 deletions

View File

@ -128,6 +128,7 @@ void INPptPrint(char *str, IFparseTree * ptree);
#define PTF_MAX 33
#define PTF_CEIL 34
#define PTF_FLOOR 35
#define PTF_NINT 36
/* The following things are used by the parser -- these are the token types the
* lexer returns.

View File

@ -156,6 +156,7 @@ static struct func {
{ "uramp", PTF_URAMP, (void(*)(void)) PTuramp } ,
{ "ceil", PTF_CEIL, (void(*)(void)) PTceil } ,
{ "floor", PTF_FLOOR, (void(*)(void)) PTfloor } ,
{ "nint", PTF_NINT, (void(*)(void)) PTnint } ,
{ "-", PTF_UMINUS, (void(*)(void)) PTuminus },
/* MW. cif function added */
{ "u2", PTF_USTEP2, (void(*)(void)) PTustep2},
@ -491,6 +492,10 @@ static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum)
arg1 = mkcon(0.0);
break;
case PTF_NINT: /* naive: D(nint(u)) = 0 */
arg1 = mkcon(0.0);
break;
/* MW. PTF_CIF for new cif function */
case PTF_USTEP2: /* ustep2=uramp(x)-uramp(x-1) ustep2'=ustep(x)-ustep(x-1) */

View File

@ -76,5 +76,6 @@ double PTge0(double arg);
double PTle0(double arg);
double PTceil(double arg);
double PTfloor(double arg);
double PTnint(double arg);
#endif

View File

@ -339,3 +339,12 @@ PTfloor(double arg1)
return (floor(arg1));
}
double
PTnint(double arg1)
{
/* round to "nearest integer",
* round half-integers to the nearest even integer
* rely on default rounding mode of IEEE 754 to do so
*/
return nearbyint(arg1);
}