Mercurial > cpython-lru_cache-weakref
annotate Python/atof.c @ 58973:db86bf39ccaa legacy-trunk
Issue 7970: When email.Parser.Parser parses a MIME message of type
message/rfc822 it turns it into an object whose body consists of
a list containing a single Message object. HeaderParser, on the
other hand, just copies the body as a string. Generator.flatten
has a special handler for the message mime type that expected the
body to be the one item list. This fails if the message was parsed
by HeaderParser. So we now check to see if the body is a string
first, and if so just we just emit it.
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Sun, 21 Feb 2010 04:23:00 +0000 |
| parents | 2dea40e40d9d |
| children | fd25030223b0 |
| rev | line source |
|---|---|
| 2396 | 1 |
| 2 /* Just in case you haven't got an atof() around... | |
| 3 This one doesn't check for bad syntax or overflow, | |
| 4 and is slow and inaccurate. | |
| 5 But it's good enough for the occasional string literal... */ | |
| 6 | |
|
18835
2dea40e40d9d
Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774.
Martin v. Löwis <martin@v.loewis.de>
parents:
14375
diff
changeset
|
7 #include "pyconfig.h" |
| 2396 | 8 |
| 9 #include <ctype.h> | |
| 10 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
11 double atof(char *s) |
| 2396 | 12 { |
| 13 double a = 0.0; | |
| 14 int e = 0; | |
| 15 int c; | |
| 16 while ((c = *s++) != '\0' && isdigit(c)) { | |
| 17 a = a*10.0 + (c - '0'); | |
| 18 } | |
| 19 if (c == '.') { | |
| 20 while ((c = *s++) != '\0' && isdigit(c)) { | |
| 21 a = a*10.0 + (c - '0'); | |
| 22 e = e-1; | |
| 23 } | |
| 24 } | |
| 25 if (c == 'e' || c == 'E') { | |
| 26 int sign = 1; | |
| 27 int i = 0; | |
| 28 c = *s++; | |
| 29 if (c == '+') | |
| 30 c = *s++; | |
| 31 else if (c == '-') { | |
| 32 c = *s++; | |
| 33 sign = -1; | |
| 34 } | |
| 35 while (isdigit(c)) { | |
| 36 i = i*10 + (c - '0'); | |
| 37 c = *s++; | |
| 38 } | |
| 39 e += i*sign; | |
| 40 } | |
| 41 while (e > 0) { | |
| 42 a *= 10.0; | |
| 43 e--; | |
| 44 } | |
| 45 while (e < 0) { | |
| 46 a *= 0.1; | |
| 47 e++; | |
| 48 } | |
| 49 return a; | |
| 50 } |
