Browse Source

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

rlar 15 years ago
parent
commit
5d302ee823
  1. 10
      ChangeLog
  2. 24
      src/xspice/mif/mifgetvalue.c

10
ChangeLog

@ -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 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: /xspice/icm/analog/file_source/ifspec.ifs:
code model with input from file added (T. Sailer) code model with input from file added (T. Sailer)
example/xspice/fstest.sp, sine.m: test of 'filesource' example/xspice/fstest.sp, sine.m: test of 'filesource'
2011-06-23 Robert Larice 2011-06-23 Robert Larice
* src/frontend/options.c , * src/frontend/options.c ,
* src/frontend/spiceif.c , * src/frontend/spiceif.c ,

24
src/xspice/mif/mifgetvalue.c

@ -253,27 +253,27 @@ static int MIFget_integer(char *token, char **err)
long l; long l;
double dtemp; double dtemp;
char *endp; char *endp;
/* long strtol(char *, char **, int); */
*err = NULL; *err = NULL;
errno = 0;
l = strtol(token, &endp, 0); /* handles base 8, 10, 16 automatically */ 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, */ /* if error, probably caused by engineering suffixes, */
/* so try parsing with INPevaluate */ /* 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));
} }

Loading…
Cancel
Save