Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b7e04a

Browse files
committed
for __SC__
1 parent c388068 commit 2b7e04a

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Python/atof.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/***********************************************************
2+
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3+
The Netherlands.
4+
5+
All Rights Reserved
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both that copyright notice and this permission notice appear in
11+
supporting documentation, and that the names of Stichting Mathematisch
12+
Centrum or CWI not be used in advertising or publicity pertaining to
13+
distribution of the software without specific, written prior permission.
14+
15+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/
24+
25+
/* Just in case you haven't got an atof() around...
26+
This one doesn't check for bad syntax or overflow,
27+
and is slow and inaccurate.
28+
But it's good enough for the occasional string literal... */
29+
30+
#ifdef HAVE_CONFIG_H
31+
#include "config.h"
32+
#endif
33+
34+
#include <ctype.h>
35+
36+
double atof(s)
37+
char *s;
38+
{
39+
double a = 0.0;
40+
int e = 0;
41+
int c;
42+
while ((c = *s++) != '\0' && isdigit(c)) {
43+
a = a*10.0 + (c - '0');
44+
}
45+
if (c == '.') {
46+
while ((c = *s++) != '\0' && isdigit(c)) {
47+
a = a*10.0 + (c - '0');
48+
e = e-1;
49+
}
50+
}
51+
if (c == 'e' || c == 'E') {
52+
int sign = 1;
53+
int i = 0;
54+
c = *s++;
55+
if (c == '+')
56+
c = *s++;
57+
else if (c == '-') {
58+
c = *s++;
59+
sign = -1;
60+
}
61+
while (isdigit(c)) {
62+
i = i*10 + (c - '0');
63+
c = *s++;
64+
}
65+
e += i*sign;
66+
}
67+
while (e > 0) {
68+
a *= 10.0;
69+
e--;
70+
}
71+
while (e < 0) {
72+
a *= 0.1;
73+
e++;
74+
}
75+
return a;
76+
}

Python/strtod.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#ifdef HAVE_CONFIG_H
2+
#include "config.h"
3+
#endif
4+
15
/* comp.sources.misc strtod(), as posted in comp.lang.tcl,
26
with bugfix for "123000.0" and acceptance of space after 'e' sign nuked.
37

0 commit comments

Comments
 (0)