Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
d49182c1
Commit
d49182c1
authored
Feb 11, 2015
by
HuangRui
Browse files
Move powersOf10 array to global.
parent
db43b1e0
Changes
1
Show whitespace changes
Inline
Side-by-side
app/libc/c_stdlib.c
View file @
d49182c1
...
...
@@ -12,8 +12,10 @@ const char *lua_init_value = "@init.lua";
// }
// void c_exit(int e){
// }
const
char
*
c_getenv
(
const
char
*
__string
){
if
(
c_strcmp
(
__string
,
"LUA_INIT"
)
==
0
){
const
char
*
c_getenv
(
const
char
*
__string
)
{
if
(
c_strcmp
(
__string
,
"LUA_INIT"
)
==
0
)
{
return
lua_init_value
;
}
return
NULL
;
...
...
@@ -55,14 +57,8 @@ const char *c_getenv(const char *__string){
#include <string.h>
//#include "mprec.h"
double
c_strtod
(
const
char
*
string
,
char
**
endPtr
)
double
powersOf10
[]
=
/* Table giving binary powers of 10. Entry */
{
int
maxExponent
=
511
;
/* Largest possible base 10 exponent. Any
* exponent larger than this will already
* produce underflow or overflow, so there's
* no need to worry about additional digits.
*/
double
powersOf10
[]
=
{
/* Table giving binary powers of 10. Entry */
10
.,
/* is 10^2^i. Used to convert decimal */
100
.,
/* exponents into floating-point numbers. */
1.0e4
,
...
...
@@ -72,7 +68,16 @@ double c_strtod(const char *string, char **endPtr)
1.0e64
,
1.0e128
,
1.0e256
};
};
double
c_strtod
(
const
char
*
string
,
char
**
endPtr
)
{
int
maxExponent
=
511
;
/* Largest possible base 10 exponent. Any
* exponent larger than this will already
* produce underflow or overflow, so there's
* no need to worry about additional digits.
*/
int
sign
,
expSign
=
FALSE
;
double
fraction
,
dblExp
,
*
d
;
register
const
char
*
p
;
...
...
@@ -98,14 +103,19 @@ double c_strtod(const char *string, char **endPtr)
*/
p
=
string
;
while
(
isspace
((
unsigned
char
)(
*
p
)))
{
while
(
isspace
((
unsigned
char
)(
*
p
)))
{
p
+=
1
;
}
if
(
*
p
==
'-'
)
{
if
(
*
p
==
'-'
)
{
sign
=
TRUE
;
p
+=
1
;
}
else
{
if
(
*
p
==
'+'
)
{
}
else
{
if
(
*
p
==
'+'
)
{
p
+=
1
;
}
sign
=
FALSE
;
...
...
@@ -120,8 +130,10 @@ double c_strtod(const char *string, char **endPtr)
for
(
mantSize
=
0
;
;
mantSize
+=
1
)
{
c
=
*
p
;
if
(
!
isdigit
(
c
))
{
if
((
c
!=
'.'
)
||
(
decPt
>=
0
))
{
if
(
!
isdigit
(
c
))
{
if
((
c
!=
'.'
)
||
(
decPt
>=
0
))
{
break
;
}
decPt
=
mantSize
;
...
...
@@ -138,44 +150,55 @@ double c_strtod(const char *string, char **endPtr)
pExp
=
p
;
p
-=
mantSize
;
if
(
decPt
<
0
)
{
if
(
decPt
<
0
)
{
decPt
=
mantSize
;
}
else
{
}
else
{
mantSize
-=
1
;
/* One of the digits was the point. */
}
if
(
mantSize
>
18
)
{
if
(
mantSize
>
18
)
{
fracExp
=
decPt
-
18
;
mantSize
=
18
;
}
else
{
}
else
{
fracExp
=
decPt
-
mantSize
;
}
if
(
mantSize
==
0
)
{
if
(
mantSize
==
0
)
{
fraction
=
0
.
0
;
p
=
string
;
goto
done
;
}
else
{
}
else
{
int
frac1
,
frac2
;
frac1
=
0
;
for
(
;
mantSize
>
9
;
mantSize
-=
1
)
{
c
=
*
p
;
p
+=
1
;
if
(
c
==
'.'
)
{
if
(
c
==
'.'
)
{
c
=
*
p
;
p
+=
1
;
}
frac1
=
10
*
frac1
+
(
c
-
'0'
);
frac1
=
10
*
frac1
+
(
c
-
'0'
);
}
frac2
=
0
;
for
(;
mantSize
>
0
;
mantSize
-=
1
)
{
c
=
*
p
;
p
+=
1
;
if
(
c
==
'.'
)
{
if
(
c
==
'.'
)
{
c
=
*
p
;
p
+=
1
;
}
frac2
=
10
*
frac2
+
(
c
-
'0'
);
frac2
=
10
*
frac2
+
(
c
-
'0'
);
}
fraction
=
(
1.0e9
*
frac1
)
+
frac2
;
}
...
...
@@ -185,29 +208,39 @@ double c_strtod(const char *string, char **endPtr)
*/
p
=
pExp
;
if
((
*
p
==
'E'
)
||
(
*
p
==
'e'
))
{
if
((
*
p
==
'E'
)
||
(
*
p
==
'e'
))
{
p
+=
1
;
if
(
*
p
==
'-'
)
{
if
(
*
p
==
'-'
)
{
expSign
=
TRUE
;
p
+=
1
;
}
else
{
if
(
*
p
==
'+'
)
{
}
else
{
if
(
*
p
==
'+'
)
{
p
+=
1
;
}
expSign
=
FALSE
;
}
if
(
!
isdigit
((
unsigned
char
)(
*
p
)))
{
if
(
!
isdigit
((
unsigned
char
)(
*
p
)))
{
p
=
pExp
;
goto
done
;
}
while
(
isdigit
((
unsigned
char
)(
*
p
)))
{
while
(
isdigit
((
unsigned
char
)(
*
p
)))
{
exp
=
exp
*
10
+
(
*
p
-
'0'
);
p
+=
1
;
}
}
if
(
expSign
)
{
if
(
expSign
)
{
exp
=
fracExp
-
exp
;
}
else
{
}
else
{
exp
=
fracExp
+
exp
;
}
...
...
@@ -218,34 +251,45 @@ double c_strtod(const char *string, char **endPtr)
* fraction.
*/
if
(
exp
<
0
)
{
if
(
exp
<
0
)
{
expSign
=
TRUE
;
exp
=
-
exp
;
}
else
{
}
else
{
expSign
=
FALSE
;
}
if
(
exp
>
maxExponent
)
{
if
(
exp
>
maxExponent
)
{
exp
=
maxExponent
;
// errno = ERANGE;
}
dblExp
=
1
.
0
;
for
(
d
=
powersOf10
;
exp
!=
0
;
exp
>>=
1
,
d
+=
1
)
{
if
(
exp
&
01
)
{
for
(
d
=
powersOf10
;
exp
!=
0
;
exp
>>=
1
,
d
+=
1
)
{
if
(
exp
&
01
)
{
dblExp
*=
*
d
;
}
}
if
(
expSign
)
{
if
(
expSign
)
{
fraction
/=
dblExp
;
}
else
{
}
else
{
fraction
*=
dblExp
;
}
done:
if
(
endPtr
!=
NULL
)
{
if
(
endPtr
!=
NULL
)
{
*
endPtr
=
(
char
*
)
p
;
}
if
(
sign
)
{
if
(
sign
)
{
return
-
fraction
;
}
return
fraction
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment