FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/Python/atof.c at master · technomalogical/python · GitHub
technomalogical
/
python
Public
forked from
glix/python
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
Python
/
atof.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (46 loc) · 815 Bytes
Breadcrumbs
python
/
Python
/
atof.c
Copy path
File metadata and controls
50 lines (46 loc) · 815 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Just in case you haven't got an atof() around...
This one doesn't check for bad syntax or overflow,
and is slow and inaccurate.
But it's good enough for the occasional string literal... */
#include
"pyconfig.h"
#include
<ctype.h>
double
atof
(
char
*
s
)
{
double
a
=
0.0
;
int
e
=
0
;
int
c
;
while
((
c
=
*
s
++
)
!=
'\0'
&&
isdigit
(
c
)) {
a
=
a
*
10.0
+
(
c
-
'0'
);
}
if
(
c
==
'.'
) {
while
((
c
=
*
s
++
)
!=
'\0'
&&
isdigit
(
c
)) {
a
=
a
*
10.0
+
(
c
-
'0'
);
e
=
e
-
1
;
}
}
if
(
c
==
'e'
||
c
==
'E'
) {
int
sign
=
1
;
int
i
=
0
;
c
=
*
s
++
;
if
(
c
==
'+'
)
c
=
*
s
++
;
else
if
(
c
==
'-'
) {
c
=
*
s
++
;
sign
=
-1
;
}
while
(
isdigit
(
c
)) {
i
=
i
*
10
+
(
c
-
'0'
);
c
=
*
s
++
;
}
e
+=
i
*
sign
;
}
while
(
e
>
0
) {
a
*=
10.0
;
e
--
;
}
while
(
e
<
0
) {
a
*=
0.1
;
e
++
;
}
return
a
;
}
Back
|
FazBrowse Home
|
New Git URL