Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
调味师
arduino-esp32
提交
d7aed639
A
arduino-esp32
项目概览
调味师
/
arduino-esp32
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
arduino-esp32
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d7aed639
编写于
10月 26, 2016
作者:
M
me-no-dev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add noniso.c implementation from ESP8266
上级
50c2ea52
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
161 addition
and
0 deletion
+161
-0
cores/esp32/noniso.c
cores/esp32/noniso.c
+161
-0
未找到文件。
cores/esp32/noniso.c
0 → 100644
浏览文件 @
d7aed639
/*
core_esp8266_noniso.c - nonstandard (but usefull) conversion functions
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 03 April 2015 by Markus Sattler
*/
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include "stdlib_noniso.h"
void
reverse
(
char
*
begin
,
char
*
end
)
{
char
*
is
=
begin
;
char
*
ie
=
end
-
1
;
while
(
is
<
ie
)
{
char
tmp
=
*
ie
;
*
ie
=
*
is
;
*
is
=
tmp
;
++
is
;
--
ie
;
}
}
char
*
ltoa
(
long
value
,
char
*
result
,
int
base
)
{
if
(
base
<
2
||
base
>
16
)
{
*
result
=
0
;
return
result
;
}
char
*
out
=
result
;
long
quotient
=
abs
(
value
);
do
{
const
long
tmp
=
quotient
/
base
;
*
out
=
"0123456789abcdef"
[
quotient
-
(
tmp
*
base
)];
++
out
;
quotient
=
tmp
;
}
while
(
quotient
);
// Apply negative sign
if
(
value
<
0
)
*
out
++
=
'-'
;
reverse
(
result
,
out
);
*
out
=
0
;
return
result
;
}
char
*
ultoa
(
unsigned
long
value
,
char
*
result
,
int
base
)
{
if
(
base
<
2
||
base
>
16
)
{
*
result
=
0
;
return
result
;
}
char
*
out
=
result
;
unsigned
long
quotient
=
value
;
do
{
const
unsigned
long
tmp
=
quotient
/
base
;
*
out
=
"0123456789abcdef"
[
quotient
-
(
tmp
*
base
)];
++
out
;
quotient
=
tmp
;
}
while
(
quotient
);
reverse
(
result
,
out
);
*
out
=
0
;
return
result
;
}
char
*
dtostrf
(
double
number
,
signed
char
width
,
unsigned
char
prec
,
char
*
s
)
{
bool
negative
=
false
;
if
(
isnan
(
number
))
{
strcpy
(
s
,
"nan"
);
return
s
;
}
if
(
isinf
(
number
))
{
strcpy
(
s
,
"inf"
);
return
s
;
}
char
*
out
=
s
;
int
fillme
=
width
;
// how many cells to fill for the integer part
if
(
prec
>
0
)
{
fillme
-=
(
prec
+
1
);
}
// Handle negative numbers
if
(
number
<
0
.
0
)
{
negative
=
true
;
fillme
--
;
number
=
-
number
;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
// I optimized out most of the divisions
double
rounding
=
2
.
0
;
for
(
uint8_t
i
=
0
;
i
<
prec
;
++
i
)
rounding
*=
10
.
0
;
rounding
=
1
.
0
/
rounding
;
number
+=
rounding
;
// Figure out how big our number really is
double
tenpow
=
1
.
0
;
int
digitcount
=
1
;
while
(
number
>=
10
.
0
*
tenpow
)
{
tenpow
*=
10
.
0
;
digitcount
++
;
}
number
/=
tenpow
;
fillme
-=
digitcount
;
// Pad unused cells with spaces
while
(
fillme
--
>
0
)
{
*
out
++
=
' '
;
}
// Handle negative sign
if
(
negative
)
*
out
++
=
'-'
;
// Print the digits, and if necessary, the decimal point
digitcount
+=
prec
;
int8_t
digit
=
0
;
while
(
digitcount
--
>
0
)
{
digit
=
(
int8_t
)
number
;
if
(
digit
>
9
)
digit
=
9
;
// insurance
*
out
++
=
(
char
)(
'0'
|
digit
);
if
((
digitcount
==
prec
)
&&
(
prec
>
0
))
{
*
out
++
=
'.'
;
}
number
-=
digit
;
number
*=
10
.
0
;
}
// make sure the string is terminated
*
out
=
0
;
return
s
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录