[Python-bugs-list] float("1.0e-309") inconsistency on win32 (PR#245)

Tim Peters tim_one@email.msn.com
Thu, 23 Mar 2000 01:43:30 -0500


> -----Original Message-----
> From: python-bugs-list-admin@python.org
> [mailto:python-bugs-list-admin@python.org]On Behalf Of
> sde@recombinant.demon.co.uk
> Sent: Wednesday, March 22, 2000 4:13 PM
> To: python-bugs-list@python.org
> Cc: bugs-py@python.org
> Subject: [Python-bugs-list] float("1.0e-309") inconsistency on win32
> (PR#245)
>
>
> Full_Name: Stephen D Evans
> Version: 1.5.2
> OS: win32
> Submission from: recombinant.demon.co.uk (212.229.73.7)
>
>
> #! /usr/bin/python
>
> # Inconsistent behaviour.
>
> # Python 1.5.2 win32 fails the second print (why not both?)
> # other versions print both expressions
>
> #              Ok  Python 1.5.2 on SuSE Linux 6.3
> #              Ok  JPython 1.1 on java1.1.7B
> # Partial failure  Python 1.5.2 win32
>
> print eval("float(1.0e-309)")
> print float("1.0e-309") # ValueError: float() literal too large: 1.0e-309

First note that these don't do the same thing:  the first passes a float to
"float", the second passes a string to "float".  Change the first to

    print eval("float('1.0e-309')")

and it gives the same bogus error as the second one.

Then it turns out the error is Microsoft's fault.  This tiny C program shows
the bug:

#include <errno.h>
#include <stdlib.h>
#include <stdio.h>

void
main()
{
    double x;
    char* dontcare;
    errno = 0;
    x = strtod("1.0e-309", &dontcare);
    printf("errno after = %d\n", errno);
    printf("x after = %g\n", x);
}

This prints

    errno after = 34
    x after = 0

when compiled & linked with MS's VC5; don't know about VC6.  Same thing for
"1.0e-308".  Works fine for "1.0e-307".  Doubt this will get fixed before MS
fixes their library.