Mercurial > cpython-lru_cache-weakref
annotate Python/atof.c @ 13658:f79434ee41fa legacy-trunk
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
declarations yet, those come later.
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Sat, 22 Jul 2000 18:47:25 +0000 |
| parents | 87ee82e5c56d |
| children | 6f6f965c5e2d |
| rev | line source |
|---|---|
| 2396 | 1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
5 All rights reserved. |
| 2396 | 6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 2396 | 9 ******************************************************************/ |
| 10 | |
| 11 /* Just in case you haven't got an atof() around... | |
| 12 This one doesn't check for bad syntax or overflow, | |
| 13 and is slow and inaccurate. | |
| 14 But it's good enough for the occasional string literal... */ | |
| 15 | |
| 16 #include "config.h" | |
| 17 | |
| 18 #include <ctype.h> | |
| 19 | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
20 double atof(char *s) |
| 2396 | 21 { |
| 22 double a = 0.0; | |
| 23 int e = 0; | |
| 24 int c; | |
| 25 while ((c = *s++) != '\0' && isdigit(c)) { | |
| 26 a = a*10.0 + (c - '0'); | |
| 27 } | |
| 28 if (c == '.') { | |
| 29 while ((c = *s++) != '\0' && isdigit(c)) { | |
| 30 a = a*10.0 + (c - '0'); | |
| 31 e = e-1; | |
| 32 } | |
| 33 } | |
| 34 if (c == 'e' || c == 'E') { | |
| 35 int sign = 1; | |
| 36 int i = 0; | |
| 37 c = *s++; | |
| 38 if (c == '+') | |
| 39 c = *s++; | |
| 40 else if (c == '-') { | |
| 41 c = *s++; | |
| 42 sign = -1; | |
| 43 } | |
| 44 while (isdigit(c)) { | |
| 45 i = i*10 + (c - '0'); | |
| 46 c = *s++; | |
| 47 } | |
| 48 e += i*sign; | |
| 49 } | |
| 50 while (e > 0) { | |
| 51 a *= 10.0; | |
| 52 e--; | |
| 53 } | |
| 54 while (e < 0) { | |
| 55 a *= 0.1; | |
| 56 e++; | |
| 57 } | |
| 58 return a; | |
| 59 } |
