Message58680
On 2007-12-15, Christian Heimes wrote:
> Christian Heimes added the comment:
>
> Mark Summerfield wrote:
> > It seems to me that Python should provide consistent results across
> > platforms wherever possible and that this is a gratuitous inconsistency
> > that makes cross-platform testing less convenient than it need be.
> >
> > I'll take a look at those functions next week.
>
> It should be fixed in the trunk and merged into py3k. 2.6 suffers from
> the same problem.
>
> By the way I have another pending patch which adds consistent handling
> of "nan" and "inf" on all platforms to float.
Hi Christian,
I made two mistakes (that I know of)---(1) I forgot that 'g' format can
produce an exponent string, and (2) I did a wrong calculation to ensure
that I didn't overflow the buffer. (Even with those mistakes Python's
test_float and test_fpformat passed fine, as did my own tests.) Anyway,
here's the fixed and hopefully final block of code. The first correction
affects the first if statement, and the second correction affects the
third if statement.
/* Ensure that the exponent is at least 3 digits,
providing the buffer is large enough for the extra zeros. */
if (format_char == 'e' || format_char == 'E' ||
format_char == 'g' || format_char == 'G') {
p = buffer;
while (*p && *p != 'e' && *p != 'E')
++p;
if (*p && (*(p + 1) == '-' || *(p + 1) == '+')) {
p += 2;
char *start = p;
int exponent_digit_count = 0;
while (*p && isdigit((unsigned char)*p)) {
++p;
++exponent_digit_count;
}
int zeros = 3 - exponent_digit_count;
if (exponent_digit_count && zeros > 0 &&
start + zeros + exponent_digit_count + 1
< buffer + buf_len) {
p = start;
memmove(p + zeros, p, exponent_digit_count + 1);
int i = 0;
for (; i < zeros; ++i)
*p++ = '0';
}
}
}
I've also attached the complete pystrtod.c file with the corrections. |
File name |
Uploaded |
pystrtod.c
|
mark,
2007-12-17.01:09:49
|
|
Date |
User |
Action |
Args |
2007-12-17 01:09:50 | mark | set | spambayes_score: 0.00535949 -> 0.00535949 recipients:
+ mark, gvanrossum, christian.heimes |
2007-12-17 01:09:50 | mark | link | issue1600 messages |
2007-12-17 01:09:49 | mark | create | |
|