diff options
author | William M. Brack <wbrack@src.gnome.org> | 2007-05-11 14:45:53 +0000 |
---|---|---|
committer | William M. Brack <wbrack@src.gnome.org> | 2007-05-11 14:45:53 +0000 |
commit | ca79788eaa34765e184801c4db50560e5a0dda91 (patch) | |
tree | 9bd383ced26d2a1cba301736850e0c0d3d3d8505 /xpath.c | |
parent | f6cf57a03b9f8b4aadeb473f8bf16c38fa6a3499 (diff) | |
download | android_external_libxml2-ca79788eaa34765e184801c4db50560e5a0dda91.tar.gz android_external_libxml2-ca79788eaa34765e184801c4db50560e5a0dda91.tar.bz2 android_external_libxml2-ca79788eaa34765e184801c4db50560e5a0dda91.zip |
enhanced the coding for xmlXPathCastNumberToString in order to produce the
* xpath.c: enhanced the coding for xmlXPathCastNumberToString
in order to produce the required number of significant digits
(bug #437179)
svn path=/trunk/; revision=3615
Diffstat (limited to 'xpath.c')
-rw-r--r-- | xpath.c | 34 |
1 files changed, 22 insertions, 12 deletions
@@ -2648,9 +2648,10 @@ xmlXPathPopExternal (xmlXPathParserContextPtr ctxt) { #define UPPER_DOUBLE 1E9 #define LOWER_DOUBLE 1E-5 +#define LOWER_DOUBLE_EXP 5 #define INTEGER_DIGITS DBL_DIG -#define FRACTION_DIGITS (DBL_DIG + 1) +#define FRACTION_DIGITS (DBL_DIG + 1 + (LOWER_DOUBLE_EXP)) #define EXPONENT_DIGITS (3 + 2) /** @@ -2701,8 +2702,16 @@ xmlXPathFormatNumber(double number, char buffer[], int buffersize) *ptr = 0; } } else { - /* 3 is sign, decimal point, and terminating zero */ - char work[DBL_DIG + EXPONENT_DIGITS + 3]; + /* + For the dimension of work, + DBL_DIG is number of significant digits + EXPONENT is only needed for "scientific notation" + 3 is sign, decimal point, and terminating zero + LOWER_DOUBLE_EXP is max number of leading zeroes in fraction + Note that this dimension is slightly (a few characters) + larger than actually necessary. + */ + char work[DBL_DIG + EXPONENT_DIGITS + 3 + LOWER_DOUBLE_EXP]; int integer_place, fraction_place; char *ptr; char *after_fraction; @@ -2725,24 +2734,25 @@ xmlXPathFormatNumber(double number, char buffer[], int buffersize) size = snprintf(work, sizeof(work),"%*.*e", integer_place, fraction_place, number); while ((size > 0) && (work[size] != 'e')) size--; - after_fraction = work + size; } else { /* Use regular notation */ - if (absolute_value > 0.0) - integer_place = 1 + (int)log10(absolute_value); - else - integer_place = 0; - fraction_place = (integer_place > 0) - ? DBL_DIG - integer_place - : DBL_DIG; + if (absolute_value > 0.0) { + integer_place = (int)log10(absolute_value); + if (integer_place > 0) + fraction_place = DBL_DIG - integer_place - 1; + else + fraction_place = DBL_DIG - integer_place; + } else { + fraction_place = 1; + } size = snprintf(work, sizeof(work), "%0.*f", fraction_place, number); - after_fraction = work + size; } /* Remove fractional trailing zeroes */ + after_fraction = work + size; ptr = after_fraction; while (*(--ptr) == '0') ; |