tiny rewrite, round to nearest integer and reset errno for strtol()

This commit is contained in:
rlar 2011-06-23 20:04:08 +00:00
parent 926a7b338c
commit 5d302ee823
2 changed files with 19 additions and 15 deletions

View File

@ -1,10 +1,14 @@
2011-06-23 Robert Larice
* src/xspice/mif/mifgetvalue.c :
tiny rewrite, round to nearest integer and reset errno for strtol()
2011-06-23 Holger Vogt
* /xspice/icm/analog/modpath.lst,
/xspice/icm/analog/file_source/cfunc.mod,
* /xspice/icm/analog/modpath.lst,
/xspice/icm/analog/file_source/cfunc.mod,
/xspice/icm/analog/file_source/ifspec.ifs:
code model with input from file added (T. Sailer)
example/xspice/fstest.sp, sine.m: test of 'filesource'
2011-06-23 Robert Larice
* src/frontend/options.c ,
* src/frontend/spiceif.c ,

View File

@ -253,27 +253,27 @@ static int MIFget_integer(char *token, char **err)
long l;
double dtemp;
char *endp;
/* long strtol(char *, char **, int); */
*err = NULL;
errno = 0;
l = strtol(token, &endp, 0); /* handles base 8, 10, 16 automatically */
if(!errno && (*endp == '\0'))
return((int) l);
/* if error, probably caused by engineering suffixes, */
/* so try parsing with INPevaluate */
if(errno || (*endp != '\0')) {
dtemp = INPevaluate(&token, &error, 1);
if(error) {
*err = "Bad integer, octal, or hex value";
l = 0;
}
else if(dtemp > 0.0)
l = (long)(dtemp + 0.5);
else
l = (long)(dtemp - 0.5);
dtemp = INPevaluate(&token, &error, 1);
if(error) {
*err = "Bad integer, octal, or hex value";
return(0);
}
return((int) l);
return((int)floor(dtemp + 0.5));
}