MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlXPathStringEvalNumber

Function xmlXPathStringEvalNumber

ThirdParty/libxml2/vtklibxml2/xpath.c:9003–9092  ·  view source on GitHub ↗

* xmlXPathStringEvalNumber: * @str: A string to scan * * [30a] Float ::= Number ('e' Digits?)? * * [30] Number ::= Digits ('.' Digits?)? * | '.' Digits * [31] Digits ::= [0-9]+ * * Compile a Number in the string * In complement of the Number expression, this function also handles * negative values : '-' Number. * * Returns the double value. */

Source from the content-addressed store, hash-verified

9001 * Returns the double value.
9002 */
9003double
9004xmlXPathStringEvalNumber(const xmlChar *str) {
9005 const xmlChar *cur = str;
9006 double ret;
9007 int ok = 0;
9008 int isneg = 0;
9009 int exponent = 0;
9010 int is_exponent_negative = 0;
9011#ifdef __GNUC__
9012 unsigned long tmp = 0;
9013 double temp;
9014#endif
9015 if (cur == NULL) return(0);
9016 while (IS_BLANK_CH(*cur)) cur++;
9017 if (*cur == '-') {
9018 isneg = 1;
9019 cur++;
9020 }
9021 if ((*cur != '.') && ((*cur < '0') || (*cur > '9'))) {
9022 return(xmlXPathNAN);
9023 }
9024
9025#ifdef __GNUC__
9026 /*
9027 * tmp/temp is a workaround against a gcc compiler bug
9028 * http://veillard.com/gcc.bug
9029 */
9030 ret = 0;
9031 while ((*cur >= '0') && (*cur <= '9')) {
9032 ret = ret * 10;
9033 tmp = (*cur - '0');
9034 ok = 1;
9035 cur++;
9036 temp = (double) tmp;
9037 ret = ret + temp;
9038 }
9039#else
9040 ret = 0;
9041 while ((*cur >= '0') && (*cur <= '9')) {
9042 ret = ret * 10 + (*cur - '0');
9043 ok = 1;
9044 cur++;
9045 }
9046#endif
9047
9048 if (*cur == '.') {
9049 int v, frac = 0, max;
9050 double fraction = 0;
9051
9052 cur++;
9053 if (((*cur < '0') || (*cur > '9')) && (!ok)) {
9054 return(xmlXPathNAN);
9055 }
9056 while (*cur == '0') {
9057 frac = frac + 1;
9058 cur++;
9059 }
9060 max = frac + MAX_FRAC;

Callers 2

xmlXPathNumberFunctionFunction · 0.85

Calls 1

powFunction · 0.50

Tested by

no test coverage detected