Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
e48fe0a0
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看板
提交
e48fe0a0
编写于
10月 12, 2016
作者:
J
jsalling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reorganize NaN and Inf printing into if-else blocks
上级
30ba118c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
32 deletion
+38
-32
src/unity.c
src/unity.c
+26
-32
test/tests/testunity.c
test/tests/testunity.c
+12
-0
未找到文件。
src/unity.c
浏览文件 @
e48fe0a0
...
@@ -251,58 +251,50 @@ void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
...
@@ -251,58 +251,50 @@ void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
/*-----------------------------------------------*/
/*-----------------------------------------------*/
#ifdef UNITY_FLOAT_VERBOSE
#ifdef UNITY_FLOAT_VERBOSE
#include <stdio.h>
#ifndef UNITY_VERBOSE_NUMBER_MAX_LENGTH
# ifdef UNITY_DOUBLE_VERBOSE
# define UNITY_VERBOSE_NUMBER_MAX_LENGTH 317
# else
# define UNITY_VERBOSE_NUMBER_MAX_LENGTH 47
# endif
#endif
/*
* char buffer[19];
* if (number > 4294967296.0 || -number > 4294967296.0)
* snprintf(buffer, sizeof buffer, "%.6e", number);
* else
* snprintf(buffer, sizeof buffer, "%.6f", number);
* UnityPrint(buffer);
*/
void
UnityPrintFloat
(
_UD
number
)
void
UnityPrintFloat
(
_UD
number
)
{
{
// char TempBuffer[UNITY_VERBOSE_NUMBER_MAX_LENGTH + 1];
// snprintf(TempBuffer, sizeof(TempBuffer), "%.6f", number);
// UnityPrint(TempBuffer);
if
(
isnan
(
number
))
{
UnityPrint
(
UnityStrNaN
);
return
;
}
if
(
number
<
0
)
if
(
number
<
0
)
{
{
UNITY_OUTPUT_CHAR
(
'-'
);
UNITY_OUTPUT_CHAR
(
'-'
);
number
=
-
number
;
number
=
-
number
;
}
}
if
(
isinf
(
number
))
UnityPrintLen
(
UnityStrInf
,
3
);
if
(
isnan
(
number
))
UnityPrint
(
UnityStrNaN
);
else
if
(
isinf
(
number
))
UnityPrintLen
(
UnityStrInf
,
3
);
else
if
(
number
<
0
.
0000005
&&
number
>
0
)
UnityPrint
(
"0.000000..."
);
/* Small number format */
else
if
(
number
<
4294967296
.
0
f
)
/* Fits in an integer */
else
if
(
number
<
4294967296
.
0
f
)
/* Fits in an integer */
{
{
_UU32
integer_part
=
(
_UU32
)
number
;
_UU32
integer_part
=
(
_UU32
)
number
;
_UD
fraction_part
=
number
-
integer_part
;
_UD
fraction_part
=
number
-
integer_part
;
_U_UINT
fraction_bits
=
(
_U_UINT
)(
fraction_part
*
1000000
.
0
f
+
0
.
5
f
);
_U_UINT
fraction_bits
=
(
_U_UINT
)(
fraction_part
*
1000000
.
0
f
+
0
.
5
f
);
if
(
fraction_bits
==
1000000
)
if
(
fraction_bits
==
1000000
)
{
{
fraction_bits
=
0
;
fraction_bits
=
0
;
integer_part
+=
1
;
integer_part
+=
1
;
}
}
_U_UINT
divisor
_int
=
100000
;
_U_UINT
divisor
=
100000
;
UnityPrintNumberUnsigned
(
integer_part
);
UnityPrintNumberUnsigned
(
integer_part
);
UNITY_OUTPUT_CHAR
(
'.'
);
UNITY_OUTPUT_CHAR
(
'.'
);
/* now mod and print, then divide divisor */
/* now mod and print, then divide divisor */
do
do
{
{
UNITY_OUTPUT_CHAR
((
char
)(
'0'
+
(
fraction_bits
/
divisor
_int
)));
UNITY_OUTPUT_CHAR
((
char
)(
'0'
+
(
fraction_bits
/
divisor
)));
fraction_bits
%=
divisor
_int
;
fraction_bits
%=
divisor
;
if
(
fraction_bits
==
0
)
break
;
// Truncate trailing 0's
if
(
fraction_bits
==
0
)
break
;
// Truncate trailing 0's
divisor_int
/=
10
;
divisor
/=
10
;
}
while
(
divisor_int
>
0
);
}
while
(
divisor
>
0
);
}
}
else
/* Won't fit in an integer type */
else
/* Won't fit in an integer type */
{
{
...
@@ -316,17 +308,19 @@ void UnityPrintFloat(_UD number)
...
@@ -316,17 +308,19 @@ void UnityPrintFloat(_UD number)
exponent
++
;
exponent
++
;
}
}
integer_part
=
(
_UU32
)(
number
/
divide
+
0
.
5
f
);
integer_part
=
(
_UU32
)(
number
/
divide
+
0
.
5
f
);
_UU32
divisor_int
=
1000000
;
_UU32
divisor
=
1000000
;
do
do
{
{
UNITY_OUTPUT_CHAR
((
char
)(
'0'
+
(
integer_part
/
divisor
_int
)));
UNITY_OUTPUT_CHAR
((
char
)(
'0'
+
(
integer_part
/
divisor
)));
integer_part
%=
divisor
_int
;
integer_part
%=
divisor
;
divisor
_int
/=
10
;
divisor
/=
10
;
if
(
divisor
_int
==
100000
)
UNITY_OUTPUT_CHAR
(
'.'
);
if
(
divisor
==
100000
)
UNITY_OUTPUT_CHAR
(
'.'
);
}
while
(
divisor
_int
>
0
);
}
while
(
divisor
>
0
);
UNITY_OUTPUT_CHAR
(
'e'
);
UNITY_OUTPUT_CHAR
(
'e'
);
UNITY_OUTPUT_CHAR
(
'+'
);
UNITY_OUTPUT_CHAR
(
'+'
);
if
(
exponent
<
10
)
UNITY_OUTPUT_CHAR
(
'0'
);
UnityPrintNumberUnsigned
(
exponent
);
UnityPrintNumberUnsigned
(
exponent
);
}
}
}
}
...
...
test/tests/testunity.c
浏览文件 @
e48fe0a0
...
@@ -3228,6 +3228,18 @@ void testNotEqualFloatArraysLengthZero(void)
...
@@ -3228,6 +3228,18 @@ void testNotEqualFloatArraysLengthZero(void)
#endif
#endif
}
}
void
testFloatVerbosePrinting
(
void
)
{
#ifdef UNITY_FLOAT_VERBOSE
UnityPrintFloat
(
123456789
.
0
f
);
UnityPrintFloat
(
100000000
.
0
f
);
UnityPrintFloat
(
65536
.
0
f
*
65536
.
0
f
);
UnityPrintFloat
(
1000000000
.
0
f
);
UnityPrintFloat
(
10000000000
.
0
f
);
UnityPrintFloat
(
9999999000
.
0
f
);
#endif
}
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ==================
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ==================
void
testDoublesWithinDelta
(
void
)
void
testDoublesWithinDelta
(
void
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录