[Python-Dev] PEP 3101: floats format 'f' and 'F' (original) (raw)
Tim Peters tim.peters at gmail.com
Wed Jul 16 20:28:04 CEST 2008
- Previous message: [Python-Dev] PEP 3101: floats format 'f' and 'F'
- Next message: [Python-Dev] Unittest PEP do's and don'ts (BDFL pronouncement)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Guido]
My best guess as to why 'F' is the same as 'f' is that somebody (could've been me :-) thought, like several others in this thread, that %f never prints an exponent. I agree that making it emit an 'E' when an exponent is used is the right thing to do. Do it now!
The C standard doesn't allow for %f (or %F) to produce an exponent. That appears to be a Python innovation. People should try their examples under their native C compiler instead (best I can tell, the idea that %f/%F can produce an exponent came only from running Python examples, never from running C examples).
For example,
""" #include <stdio.h>
int main() { printf("%f\n", 1e300); } """
Under the Cygwin gcc, that displays (the admittedly atrocious, but that's why people shouldn't use %f inappropriately to begin with ;-)):
100000000000000005250476025520442024870446900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000.000000
As far as C is concerned, the only difference between %f and %F is:
The F conversion specifier produces INF, INFINITY, or NAN instead of inf,
infinity, or nan, respectively
- Previous message: [Python-Dev] PEP 3101: floats format 'f' and 'F'
- Next message: [Python-Dev] Unittest PEP do's and don'ts (BDFL pronouncement)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]