Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
74ba7028
T
Third Party Unity
项目概览
OpenHarmony
/
Third Party Unity
1 年多 前同步成功
通知
36
Star
144
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Unity
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
74ba7028
编写于
9月 14, 2017
作者:
J
John Lindgren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve accuracy of UnityPrintFloat() for common cases.
上级
8ff74d60
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
15 deletion
+43
-15
src/unity.c
src/unity.c
+18
-3
test/tests/testunity.c
test/tests/testunity.c
+25
-12
未找到文件。
src/unity.c
浏览文件 @
74ba7028
...
...
@@ -283,9 +283,9 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
else
if
(
isinf
(
number
))
UnityPrint
(
"inf"
);
else
{
UNITY_INT32
n
=
0
;
int
exponent
=
0
;
int
decimals
,
digits
;
UNITY_INT32
n
;
char
buf
[
16
];
/*
...
...
@@ -295,7 +295,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
* (exactly) the remaining power of 10 and perform one more
* multiplication or division.
*/
if
(
number
<
1
e6
f
)
if
(
number
<
1
.
0
f
)
{
UNITY_DOUBLE
factor
=
1
.
0
f
;
...
...
@@ -313,9 +313,24 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
number
/=
divisor
;
}
else
{
/*
* In this range, we can split off the integer part before
* doing any multiplications. This reduces rounding error by
* freeing up significant bits in the fractional part.
*/
UNITY_DOUBLE
factor
=
1
.
0
f
;
n
=
(
UNITY_INT32
)
number
;
number
-=
(
UNITY_DOUBLE
)
n
;
while
(
n
<
1000000
)
{
n
*=
10
;
factor
*=
10
.
0
f
;
exponent
--
;
}
number
*=
factor
;
}
/* round to nearest integer */
n
=
((
UNITY_INT32
)(
number
+
number
)
+
1
)
/
2
;
n
+
=
((
UNITY_INT32
)(
number
+
number
)
+
1
)
/
2
;
if
(
n
>
9999999
)
{
n
=
1000000
;
...
...
test/tests/testunity.c
浏览文件 @
74ba7028
...
...
@@ -4543,20 +4543,33 @@ static void printFloatValue(float f)
/* We print all NaN's as "nan", not "-nan" */
if
(
strcmp
(
expected
,
"-nan"
)
==
0
)
strcpy
(
expected
,
"nan"
);
/* Allow for relative error of +/-2.5e-7 */
strcpy
(
expected_lower
,
expected
);
strcpy
(
expected_lower2
,
expected
);
strcpy
(
expected_lower3
,
expected
);
strcpy
(
expected_higher
,
expected
);
strcpy
(
expected_higher2
,
expected
);
strcpy
(
expected_higher3
,
expected
);
/* Allow for rounding differences in the last digit */
double
lower
=
(
double
)
f
*
0
.
99999995
;
double
lower2
=
(
double
)
f
*
0
.
99999985
;
double
lower3
=
(
double
)
f
*
0
.
99999975
;
double
higher
=
(
double
)
f
*
1
.
00000005
;
double
higher2
=
(
double
)
f
*
1
.
00000015
;
double
higher3
=
(
double
)
f
*
1
.
00000025
;
if
(
isfinite
(
lower
))
sprintf
(
expected_lower
,
"%.7g"
,
lower
);
else
strcpy
(
expected_lower
,
expected
);
if
(
isfinite
(
lower2
))
sprintf
(
expected_lower2
,
"%.7g"
,
lower2
);
else
strcpy
(
expected_lower2
,
expected
);
if
(
isfinite
(
lower3
))
sprintf
(
expected_lower3
,
"%.7g"
,
lower3
);
else
strcpy
(
expected_lower3
,
expected
);
if
(
isfinite
(
higher
))
sprintf
(
expected_higher
,
"%.7g"
,
higher
);
else
strcpy
(
expected_higher
,
expected
);
if
(
isfinite
(
higher2
))
sprintf
(
expected_higher2
,
"%.7g"
,
higher2
);
else
strcpy
(
expected_higher2
,
expected
);
if
(
isfinite
(
higher3
))
sprintf
(
expected_higher3
,
"%.7g"
,
higher3
);
else
strcpy
(
expected_higher3
,
expected
);
if
(
isfinite
(
lower
))
sprintf
(
expected_lower
,
"%.7g"
,
lower
);
if
(
isfinite
(
higher
))
sprintf
(
expected_higher
,
"%.7g"
,
higher
);
/* Outside [1,10000000] allow for relative error of +/-2.5e-7 */
if
(
f
<
1
.
0
||
f
>
10000000
)
{
double
lower2
=
(
double
)
f
*
0
.
99999985
;
double
lower3
=
(
double
)
f
*
0
.
99999975
;
double
higher2
=
(
double
)
f
*
1
.
00000015
;
double
higher3
=
(
double
)
f
*
1
.
00000025
;
if
(
isfinite
(
lower2
))
sprintf
(
expected_lower2
,
"%.7g"
,
lower2
);
if
(
isfinite
(
lower3
))
sprintf
(
expected_lower3
,
"%.7g"
,
lower3
);
if
(
isfinite
(
higher2
))
sprintf
(
expected_higher2
,
"%.7g"
,
higher2
);
if
(
isfinite
(
higher3
))
sprintf
(
expected_higher3
,
"%.7g"
,
higher3
);
}
if
(
strcmp
(
expected
,
getBufferPutcharSpy
())
!=
0
&&
strcmp
(
expected_lower
,
getBufferPutcharSpy
())
!=
0
&&
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录