annotate Python/atof.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents fd25030223b0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2396
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Just in case you haven't got an atof() around...
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 This one doesn't check for bad syntax or overflow,
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 and is slow and inaccurate.
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 But it's good enough for the occasional string literal... */
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #include <ctype.h>
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
13 double a = 0.0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
14 int e = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
15 int c;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
16 while ((c = *s++) != '\0' && isdigit(c)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
17 a = a*10.0 + (c - '0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
18 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
19 if (c == '.') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
20 while ((c = *s++) != '\0' && isdigit(c)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
21 a = a*10.0 + (c - '0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
22 e = e-1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
23 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
24 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
25 if (c == 'e' || c == 'E') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
26 int sign = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
27 int i = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
28 c = *s++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
29 if (c == '+')
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
30 c = *s++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
31 else if (c == '-') {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
32 c = *s++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
33 sign = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
34 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
35 while (isdigit(c)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
36 i = i*10 + (c - '0');
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
37 c = *s++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
38 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
39 e += i*sign;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
40 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
41 while (e > 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
42 a *= 10.0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
43 e--;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
44 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
45 while (e < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
46 a *= 0.1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
47 e++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
48 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 18835
diff changeset
49 return a;
2396
29ca45eb3ab7 for __SC__
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 }