Mercurial > cpython-lru_cache-weakref
annotate Python/strtod.c @ 45852:30c4e1ca8421
Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61431 | vinay.sajip | 2008-03-16 22:35:58 +0100 (So, 16 Mär 2008) | 1 line
Clarified documentation on use of shutdown().
........
r61433 | mark.summerfield | 2008-03-17 09:28:15 +0100 (Mo, 17 Mär 2008) | 5 lines
Added a footnote to each pointing out that for XML output if an encoding
string is given it should conform to the appropriate XML standards---for
example, "UTF-8" is okay, but "UTF8" is not.
........
r61434 | eric.smith | 2008-03-17 12:01:01 +0100 (Mo, 17 Mär 2008) | 7 lines
Issue 2264: empty float presentation type needs to have at least one digit past the decimal point.
Added "Z" format_char to PyOS_ascii_formatd to support empty float presentation type.
Renamed buf_size in PyOS_ascii_formatd to more accurately reflect it's meaning.
Modified format.__float__ to use the new "Z" format as the default.
Added test cases.
........
r61435 | eric.smith | 2008-03-17 13:14:29 +0100 (Mo, 17 Mär 2008) | 2 lines
Reformated lines > 79 chars.
Deleted unused macro ISXDIGIT.
........
r61436 | jeffrey.yasskin | 2008-03-17 15:40:53 +0100 (Mo, 17 Mär 2008) | 13 lines
Allow Gnu gcc's to build python on OSX by removing -Wno-long-double,
-no-cpp-precomp, and -mno-fused-madd from configure.
* r22183 added -no-cpp-precomp, which
http://gcc.gnu.org/ml/gcc/2005-12/msg00368.html claims hasn't been
needed since gcc-3.1.
* r25607 added -Wno-long-double to avoid a warning in
Include/objimpl.h (issue 525481). The long double is still there,
but OSX 10.4's gcc no longer warns about it.
* r33666 fixed issue 775892 on OSX 10.3 by adding -mno-fused-madd,
which changed the sign of some float 0s. Tim Peters said it wasn't
a real issue anyway, and it no longer causes test failures.
Fixes issue #1779871.
........
r61439 | martin.v.loewis | 2008-03-17 17:31:57 +0100 (Mo, 17 Mär 2008) | 2 lines
Add Trent Nelson.
........
r61444 | travis.oliphant | 2008-03-17 18:36:12 +0100 (Mo, 17 Mär 2008) | 1 line
Add necessary headers to back-port new buffer protocol to Python 2.6
........
r61449 | gregory.p.smith | 2008-03-17 19:48:05 +0100 (Mo, 17 Mär 2008) | 8 lines
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
regardless of the native sizeof(long) used in the integer object.
This somewhat odd behavior of returning a signed is maintained in 2.x for
compatibility reasons of always returning an integer rather than a long object.
Fixes Issue1202 for Python 2.6
........
r61450 | neal.norwitz | 2008-03-17 20:02:45 +0100 (Mo, 17 Mär 2008) | 3 lines
Use a buffer large enough to ensure we don't overrun, even if the value
is outside the range we expect.
........
r61453 | steven.bethard | 2008-03-17 20:33:11 +0100 (Mo, 17 Mär 2008) | 1 line
Document unicode.isnumeric() and unicode.isdecimal() (issue2326)
........
r61458 | neal.norwitz | 2008-03-17 21:22:43 +0100 (Mo, 17 Mär 2008) | 5 lines
Issue 2321: reduce memory usage (increase the memory that is returned
to the system) by using pymalloc for the data of unicode objects.
Will backport.
........
r61465 | martin.v.loewis | 2008-03-17 22:55:30 +0100 (Mo, 17 Mär 2008) | 2 lines
Add David Wolever.
........
r61468 | gregory.p.smith | 2008-03-18 01:20:01 +0100 (Di, 18 Mär 2008) | 3 lines
Fix the IOError message text when opening a file with an invalid filename.
Error reported by Ilan Schnell.
........
r61471 | brett.cannon | 2008-03-18 02:00:07 +0100 (Di, 18 Mär 2008) | 2 lines
Convert test_strftime, test_getargs, and test_pep247 to use unittest.
........
r61472 | jeffrey.yasskin | 2008-03-18 02:09:59 +0100 (Di, 18 Mär 2008) | 2 lines
Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster.
........
r61473 | brett.cannon | 2008-03-18 02:50:25 +0100 (Di, 18 Mär 2008) | 2 lines
Convert test_dummy_threading and test_dbm to unittest.
........
r61474 | brett.cannon | 2008-03-18 02:58:56 +0100 (Di, 18 Mär 2008) | 2 lines
Move test_extcall to doctest.
........
r61480 | brett.cannon | 2008-03-18 04:46:22 +0100 (Di, 18 Mär 2008) | 2 lines
test_errno was a no-op test; now it actually tests things and uses unittest.
........
r61483 | brett.cannon | 2008-03-18 05:09:00 +0100 (Di, 18 Mär 2008) | 3 lines
Remove our implementation of memmove() and strerror(); both are in the C89
standard library.
........
r61484 | brett.cannon | 2008-03-18 05:16:06 +0100 (Di, 18 Mär 2008) | 2 lines
The output directory for tests that compare against stdout is now gone!
........
r61488 | jeffrey.yasskin | 2008-03-18 05:29:35 +0100 (Di, 18 Mär 2008) | 2 lines
Block the "socket.ssl() is deprecated" warning from test_socket_ssl.
........
r61495 | jeffrey.yasskin | 2008-03-18 05:56:06 +0100 (Di, 18 Mär 2008) | 4 lines
Speed test_thread up from 51.328s to 0.081s by reducing its sleep times. We
still sleep at all to make it likely that all threads are active at the same
time.
........
r61496 | jeffrey.yasskin | 2008-03-18 06:12:41 +0100 (Di, 18 Mär 2008) | 4 lines
Speed up test_dict by about 10x by only checking selected dict literal sizes,
instead of every integer from 0 to 400. Exhaustive testing wastes time without
providing enough more assurance that the code is correct.
........
r61498 | neal.norwitz | 2008-03-18 06:20:29 +0100 (Di, 18 Mär 2008) | 1 line
Try increasing the timeout to reduce the flakiness of this test.
........
r61503 | brett.cannon | 2008-03-18 06:43:04 +0100 (Di, 18 Mär 2008) | 2 lines
Improve the error message for a test that failed on the S-390 Debian buildbot.
........
r61504 | jeffrey.yasskin | 2008-03-18 06:45:40 +0100 (Di, 18 Mär 2008) | 3 lines
Add a -S/--slow flag to regrtest to have it print the 10 slowest tests with
their times.
........
r61507 | neal.norwitz | 2008-03-18 07:03:46 +0100 (Di, 18 Mär 2008) | 1 line
Add some info to the failure messages
........
r61509 | trent.nelson | 2008-03-18 08:02:12 +0100 (Di, 18 Mär 2008) | 1 line
Issue 2286: bump up the stack size of the 64-bit debug python_d.exe to 2100000. The default value of 200000 causes a stack overflow at 1965 iterations of r_object() in marshal.c, 35 iterations before the 2000 limit enforced by MAX_MARSHAL_STACK_DEPTH.
........
r61510 | trent.nelson | 2008-03-18 08:32:47 +0100 (Di, 18 Mär 2008) | 5 lines
The behaviour of winsound.Beep() seems to differ between different versions of Windows when there's either:
a) no sound card entirely
b) legacy beep driver has been disabled
c) the legacy beep driver has been uninstalled
Sometimes RuntimeErrors are raised, sometimes they're not. If _have_soundcard() returns False, don't expect winsound.Beep() to raise a RuntimeError, as this clearly isn't the case, as demonstrated by the various Win32 XP buildbots.
........
r61515 | martin.v.loewis | 2008-03-18 13:20:15 +0100 (Di, 18 Mär 2008) | 2 lines
norwitz-amd64 (gentoo) has EREMOTEIO.
........
r61516 | martin.v.loewis | 2008-03-18 13:45:37 +0100 (Di, 18 Mär 2008) | 2 lines
Add more Linux error codes.
........
r61517 | martin.v.loewis | 2008-03-18 14:05:03 +0100 (Di, 18 Mär 2008) | 2 lines
Add WSA errors.
........
r61518 | martin.v.loewis | 2008-03-18 14:16:05 +0100 (Di, 18 Mär 2008) | 2 lines
Note that the stderr output of the test is intentional.
........
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Tue, 18 Mar 2008 15:15:01 +0000 |
| parents | 2a821e001a2b |
| children | e38335d4df91 0d14827bcc0d |
| rev | line source |
|---|---|
|
18835
2dea40e40d9d
Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774.
Martin v. Löwis <martin@v.loewis.de>
parents:
13658
diff
changeset
|
1 #include "pyconfig.h" |
| 2396 | 2 |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
3 /* comp.sources.misc strtod(), as posted in comp.lang.tcl, |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
4 with bugfix for "123000.0" and acceptance of space after 'e' sign nuked. |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
5 |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
6 ************************************************************ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
7 * YOU MUST EDIT THE MACHINE-DEPENDENT DEFINITIONS BELOW!!! * |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
8 ************************************************************ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
9 */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
10 |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
11 /* File : stdtod.c (Modified version of str2dbl.c) |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
12 Author : Richard A. O'Keefe @ Quintus Computer Systems, Inc. |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
13 Updated: Tuesday August 2nd, 1988 |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
14 Defines: double strtod (char *str, char**ptr) |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
15 */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
16 |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
17 /* This is an implementation of the strtod() function described in the |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
18 System V manuals, with a different name to avoid linker problems. |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
19 All that str2dbl() does itself is check that the argument is well-formed |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
20 and is in range. It leaves the work of conversion to atof(), which is |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
21 assumed to exist and deliver correct results (if they can be represented). |
| 208 | 22 |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
23 There are two reasons why this should be provided to the net: |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
24 (a) some UNIX systems do not yet have strtod(), or do not have it |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
25 available in the BSD "universe" (but they do have atof()). |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
26 (b) some of the UNIX systems that *do* have it get it wrong. |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
27 (some crash with large arguments, some assign the wrong *ptr value). |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
28 There is a reason why *we* are providing it: we need a correct version |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
29 of strtod(), and if we give this one away maybe someone will look for |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
30 mistakes in it and fix them for us (:-). |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
31 */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
32 |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
33 /* The following constants are machine-specific. MD{MIN,MAX}EXPT are |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
34 integers and MD{MIN,MAX}FRAC are strings such that |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
35 0.${MDMAXFRAC}e${MDMAXEXPT} is the largest representable double, |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
36 0.${MDMINFRAC}e${MDMINEXPT} is the smallest representable +ve double |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
37 MD{MIN,MAX}FRAC must not have any trailing zeros. |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
38 The values here are for IEEE-754 64-bit floats. |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
39 It is not perfectly clear to me whether an IEEE infinity should be |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
40 returned for overflow, nor what a portable way of writing one is, |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
41 so HUGE is just 0.MAXFRAC*10**MAXEXPT (this seems still to be the |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
42 UNIX convention). |
|
548
83046664160e
Clear errno, just to be sure.
Guido van Rossum <guido@python.org>
parents:
514
diff
changeset
|
43 |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
44 I do know about <values.h>, but the whole point of this file is that |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
45 we can't always trust that stuff to be there or to be correct. |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
46 */ |
|
45244
2a821e001a2b
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
39442
diff
changeset
|
47 static int MDMINEXPT = -323; |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
48 static char MDMINFRAC[] = "494065645841246544"; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
49 static double ZERO = 0.0; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
50 |
|
45244
2a821e001a2b
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
39442
diff
changeset
|
51 static int MDMAXEXPT = 309; |
|
749
32085edd77a7
fix HUGE and MAXVAL (suggested by Tim Peters)
Guido van Rossum <guido@python.org>
parents:
595
diff
changeset
|
52 static char MDMAXFRAC[] = "17976931348623157"; |
|
32085edd77a7
fix HUGE and MAXVAL (suggested by Tim Peters)
Guido van Rossum <guido@python.org>
parents:
595
diff
changeset
|
53 static double HUGE = 1.7976931348623157e308; |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
54 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
55 extern double atof(const char *); /* Only called when result known to be ok */ |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
56 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
18835
diff
changeset
|
57 #ifdef HAVE_ERRNO_H |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
58 #include <errno.h> |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
4043
diff
changeset
|
59 #endif |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
60 extern int errno; |
| 208 | 61 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
62 double strtod(char *str, char **ptr) |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
63 { |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
64 int sign, scale, dotseen; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
65 int esign, expt; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
66 char *save; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
67 register char *sp, *dp; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
68 register int c; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
69 char *buforg, *buflim; |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
10530
diff
changeset
|
70 char buffer[64]; /* 45-digit significant + */ |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
71 /* 13-digit exponent */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
72 sp = str; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
73 while (*sp == ' ') sp++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
74 sign = 1; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
75 if (*sp == '-') sign -= 2, sp++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
76 dotseen = 0, scale = 0; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
77 dp = buffer; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
78 *dp++ = '0'; *dp++ = '.'; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
79 buforg = dp, buflim = buffer+48; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
80 for (save = sp; c = *sp; sp++) |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
81 if (c == '.') { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
82 if (dotseen) break; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
83 dotseen++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
84 } else |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
85 if ((unsigned)(c-'0') > (unsigned)('9'-'0')) { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
86 break; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
87 } else |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
88 if (c == '0') { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
89 if (dp != buforg) { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
90 /* This is not the first digit, so we want to keep it */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
91 if (dp < buflim) *dp++ = c; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
92 if (!dotseen) scale++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
93 } else { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
94 /* No non-zero digits seen yet */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
95 /* If a . has been seen, scale must be adjusted */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
96 if (dotseen) scale--; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
97 } |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
98 } else { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
99 /* This is a nonzero digit, so we want to keep it */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
100 if (dp < buflim) *dp++ = c; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
101 /* If it precedes a ., scale must be adjusted */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
102 if (!dotseen) scale++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
103 } |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
104 if (sp == save) { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
105 if (ptr) *ptr = str; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
106 errno = EDOM; /* what should this be? */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
107 return ZERO; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
108 } |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
109 |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
110 while (dp > buforg && dp[-1] == '0') --dp; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
111 if (dp == buforg) *dp++ = '0'; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
112 *dp = '\0'; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
113 /* Now the contents of buffer are |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
114 +--+--------+-+--------+ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
115 |0.|fraction|\|leftover| |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
116 +--+--------+-+--------+ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
117 ^dp points here |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
118 where fraction begins with 0 iff it is "0", and has at most |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
119 45 digits in it, and leftover is at least 16 characters. |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
120 */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
121 save = sp, expt = 0, esign = 1; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
122 do { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
123 c = *sp++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
124 if (c != 'e' && c != 'E') break; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
125 c = *sp++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
126 if (c == '-') esign -= 2, c = *sp++; else |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
127 if (c == '+' /* || c == ' ' */ ) c = *sp++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
128 if ((unsigned)(c-'0') > (unsigned)('9'-'0')) break; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
129 while (c == '0') c = *sp++; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
130 for (; (unsigned)(c-'0') <= (unsigned)('9'-'0'); c = *sp++) |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
131 expt = expt*10 + c-'0'; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
132 if (esign < 0) expt = -expt; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
133 save = sp-1; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
134 } while (0); |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
135 if (ptr) *ptr = save; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
136 expt += scale; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
137 /* Now the number is sign*0.fraction*10**expt */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
138 errno = ERANGE; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
139 if (expt > MDMAXEXPT) { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
140 return HUGE*sign; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
141 } else |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
142 if (expt == MDMAXEXPT) { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
143 if (strcmp(buforg, MDMAXFRAC) > 0) return HUGE*sign; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
144 } else |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
145 if (expt < MDMINEXPT) { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
146 return ZERO*sign; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
147 } else |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
148 if (expt == MDMINEXPT) { |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
149 if (strcmp(buforg, MDMINFRAC) < 0) return ZERO*sign; |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
150 } |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
151 /* We have now established that the number can be */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
152 /* represented without overflow or underflow */ |
|
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
153 (void) sprintf(dp, "E%d", expt); |
|
548
83046664160e
Clear errno, just to be sure.
Guido van Rossum <guido@python.org>
parents:
514
diff
changeset
|
154 errno = 0; |
|
595
f9cdeebfcb67
New version from the net.
Guido van Rossum <guido@python.org>
parents:
548
diff
changeset
|
155 return atof(buffer)*sign; |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
156 } |
