[Baypiggies] scientific notation: string to int

Andrew Dalke dalke at dalkescientific.com
Thu Dec 9 00:53:46 CET 2010


On Dec 8, 2010, at 11:46 PM, Keith Dart wrote:
> Earlier versions, also:
> 
>>>> import sys
>>>> sys.version
> '2.4.3 (#1, Nov 11 2010, 13:34:43) \n[GCC 4.1.2 20080704 (Red Hat4.1.2-48)]'
>>>> float('2.96116E+11')
> 296116000000.0

but not 0.9.1 ;)

[xavier:~/ftps/python-0.9.1] dalke% ./src/python
>>> eval('2.96116E+11')       
296116000000.0
>>> float('2.96116E+11')
Unhandled exception: type error: float() argument must be float or int
Stack backtrace (innermost last):
  File "<stdin>", line 1
>>> 

There was once upon a time no other way to convert a "float" to a float.

[xavier:~/ftps/python-0.9.1] dalke% grep -r  atof .
./src/compile.c:       extern double atof();
./src/compile.c:               return newfloatobject(atof(s));
Binary file ./src/compile.o matches
Binary file ./src/libpython.a matches
Binary file ./src/python matches
[xavier:~/ftps/python-0.9.1] dalke% grep -r  strtod .
[xavier:~/ftps/python-0.9.1] dalke% fgrep -r '%f'  .
[xavier:~/ftps/python-0.9.1] dalke% 



				Andrew
				dalke at dalkescientific.com




More information about the Baypiggies mailing list