RE: [xml] Test comparison fails on value (-2147483648)



On Sun, 26 Aug 2001 Chris_Poblete Dell com wrote:

Consider the ff. for the tag <xsl:when test="OutputWatts &lt; 0">
     OutputWatts            Evaluation
      -21474836                pass
      -214748364               pass
      -2147483648             (FAIL)
      -21474836489             pass
      -2147483648999           pass
      -2147483648999999999999  pass
The above values of OutputWatts are all negative numbers and
no matter how many digits there are, it fails at -2147483648
since an int is used temporary buffer.

Sorry to barge in here, but I did a little test:

test.c
---
void main(void)
{
  int i=-2147483648;
  printf("%d, %f\n", i, (double) i);
  printf("%d. %d\n", i<0, ((double) i)<0);
};
---

gcc test.c -o test
---
test.c: In function `main':
test.c:3: warning: decimal constant is so large that it is unsigned
test.c:2: warning: return type of `main' is not `int'
---

./test
---
-2147483648, -2147483648.000000
1. 1
---

Does that seem to be working?

Is there a reason why the function "atof" or "strtod" is not used instead?
These functions are supported in Linux, Windows, and Netware.
Sample code is:
{
  double retval;
  retval = strtod(str, (char**)NULL);
  if (retval == HUGE_VAL)
    return xmlXPathNAN;
  else
    return retval;
}

Because they're ugly, plus doing the conversion manually helps catch errors
sooner then checking if nptr is in endptr or whatnot after the conversion has
not happened.

-- 
Ignacio Vazquez-Abrams  <ignacio openservices net>






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]