Browse Source

round to next nearest integer for the rise, fall and cross arguments of `measure'

Simon Guan reported
  Bug item #3509528, `Meas goes wrong when put in a while loop'

In a .control block a `let' variable was passed to the `measure' command.

The value of this variable would have been a plain integer,
  yet it was converted internally to an internal ascii representation
    with exponential representation  (203 ==> 2.03e2)
  and then processed by `ft_numparse()' where it was converted back to
    double floating point.
  Because the intermediate 2.03 has
    no exact representation in the space of double floating point numbers
    this conversion was lossy and resulted in a non-integer value.
  This non-integer was then truncated towards minus infinity in com_measure
    yielding an error of -1

This commit implements round to nearest in com_measure2
  to avoid the problem.

FIXME,
  the internal intermediate conversion of double floating point machine
    values to ascii representations must be dropped,
  or replaced with an exact/lossless ascii representation.
    (for example GNU printf/scanf %a or 64bit hexadecimal representation)
rlar 14 years ago
parent
commit
a1ea1b3193
  1. 9
      src/frontend/com_measure2.c

9
src/frontend/com_measure2.c

@ -296,7 +296,6 @@ int measure_extract_variables( char *line )
* + <CROSS=# | CROSS=LAST> <RISE=#|RISE=LAST> <FALL=#|FALL=LAST>
* ----------------------------------------------------------------- */
int len ; /* length of string */
int status ; /* return status */
char *item ; /* parsing item */
char *measure ; /* measure keyword */
@ -332,7 +331,7 @@ int measure_extract_variables( char *line )
variable2 = NULL;
if (*line == '=') variable2 = gettok_iv(&line) ;
if( variable ){
len = (int) strlen(item);
size_t len = strlen(item);
if( item[len-1] == '=' ){
} else {
/* We may have something like V(n1)=1
@ -1159,15 +1158,15 @@ static int measure_parse_stdParams (
}
if(strcasecmp(pName,"RISE")==0) {
meas->m_rise = (int)engVal1;
meas->m_rise = (int)floor(engVal1 + 0.5);
meas->m_fall = -1;
meas->m_cross = -1;
} else if(strcasecmp(pName,"FALL")==0) {
meas->m_fall = (int)engVal1;
meas->m_fall = (int)floor(engVal1 + 0.5);
meas->m_rise = -1;
meas->m_cross = -1;
} else if(strcasecmp(pName,"CROSS")==0) {
meas->m_cross = (int)engVal1;
meas->m_cross = (int)floor(engVal1 + 0.5);
meas->m_rise = -1;
meas->m_fall = -1;
} else if(strcasecmp(pName,"VAL")==0) {

Loading…
Cancel
Save