Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
f433480f
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看板
未验证
提交
f433480f
编写于
11月 28, 2018
作者:
M
Mark VanderVoord
提交者:
GitHub
11月 28, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #299 from jlindgren90/float-printing
Allow UnityPrintFloat() to print a 7th digit.
上级
8e0f54d2
39fbd13c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
242 addition
and
79 deletion
+242
-79
src/unity.c
src/unity.c
+70
-14
test/tests/testunity.c
test/tests/testunity.c
+172
-65
未找到文件。
src/unity.c
浏览文件 @
f433480f
...
...
@@ -262,13 +262,25 @@ void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number)
/*-----------------------------------------------*/
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
/* This function prints a floating-point value in a format similar to
* printf("%.6g"). It can work with either single- or double-precision,
* but for simplicity, it prints only 6 significant digits in either case.
* Printing more than 6 digits accurately is hard (at least in the single-
* precision case) and isn't attempted here. */
/*
* This function prints a floating-point value in a format similar to
* printf("%.7g") on a single-precision machine or printf("%.9g") on a
* double-precision machine. The 7th digit won't always be totally correct
* in single-precision operation (for that level of accuracy, a more
* complicated algorithm would be needed).
*/
void
UnityPrintFloat
(
const
UNITY_DOUBLE
input_number
)
{
#ifdef UNITY_INCLUDE_DOUBLE
static
const
int
sig_digits
=
9
;
static
const
UNITY_INT32
min_scaled
=
100000000
;
static
const
UNITY_INT32
max_scaled
=
1000000000
;
#else
static
const
int
sig_digits
=
7
;
static
const
UNITY_INT32
min_scaled
=
1000000
;
static
const
UNITY_INT32
max_scaled
=
10000000
;
#endif
UNITY_DOUBLE
number
=
input_number
;
/* print minus sign (including for negative zero) */
...
...
@@ -293,27 +305,71 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
}
else
{
UNITY_INT32
n_int
=
0
,
n
;
int
exponent
=
0
;
int
decimals
,
digits
;
UNITY_INT32
n
;
char
buf
[
16
]
=
{
0
};
/* scale up or down by powers of 10 */
while
(
number
<
100000
.
0
f
/
1e6
f
)
{
number
*=
1e6
f
;
exponent
-=
6
;
}
while
(
number
<
100000
.
0
f
)
{
number
*=
10
.
0
f
;
exponent
--
;
}
while
(
number
>
1000000
.
0
f
*
1e6
f
)
{
number
/=
1e6
f
;
exponent
+=
6
;
}
while
(
number
>
1000000
.
0
f
)
{
number
/=
10
.
0
f
;
exponent
++
;
}
/*
* Scale up or down by powers of 10. To minimize rounding error,
* start with a factor/divisor of 10^10, which is the largest
* power of 10 that can be represented exactly. Finally, compute
* (exactly) the remaining power of 10 and perform one more
* multiplication or division.
*/
if
(
number
<
1
.
0
f
)
{
UNITY_DOUBLE
factor
=
1
.
0
f
;
while
(
number
<
(
UNITY_DOUBLE
)
max_scaled
/
1e10
f
)
{
number
*=
1e10
f
;
exponent
-=
10
;
}
while
(
number
*
factor
<
(
UNITY_DOUBLE
)
min_scaled
)
{
factor
*=
10
.
0
f
;
exponent
--
;
}
number
*=
factor
;
}
else
if
(
number
>
(
UNITY_DOUBLE
)
max_scaled
)
{
UNITY_DOUBLE
divisor
=
1
.
0
f
;
while
(
number
>
(
UNITY_DOUBLE
)
min_scaled
*
1e10
f
)
{
number
/=
1e10
f
;
exponent
+=
10
;
}
while
(
number
/
divisor
>
(
UNITY_DOUBLE
)
max_scaled
)
{
divisor
*=
10
.
0
f
;
exponent
++
;
}
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_int
=
(
UNITY_INT32
)
number
;
number
-=
(
UNITY_DOUBLE
)
n_int
;
while
(
n_int
<
min_scaled
)
{
n_int
*=
10
;
factor
*=
10
.
0
f
;
exponent
--
;
}
number
*=
factor
;
}
/* round to nearest integer */
n
=
((
UNITY_INT32
)(
number
+
number
)
+
1
)
/
2
;
if
(
n
>
999999
)
#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
/* round to even if exactly between two integers */
if
((
n
&
1
)
&&
((
UNITY_DOUBLE
)
n
-
number
==
0
.
5
f
))
n
--
;
#endif
n
+=
n_int
;
if
(
n
>=
max_scaled
)
{
n
=
100000
;
n
=
min_scaled
;
exponent
++
;
}
/* determine where to place decimal point */
decimals
=
(
exponent
<=
0
&&
exponent
>=
-
9
)
?
-
exponent
:
5
;
decimals
=
(
exponent
<=
0
&&
exponent
>=
-
(
sig_digits
+
3
))
?
-
exponent
:
(
sig_digits
-
1
)
;
exponent
+=
decimals
;
/* truncate trailing zeroes after decimal point */
...
...
test/tests/testunity.c
浏览文件 @
f433480f
...
...
@@ -4497,49 +4497,69 @@ void testNotEqualFloatEachEqualLengthZero(void)
void
testFloatPrinting
(
void
)
{
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0"
,
0
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.99e-07"
,
0
.
0000004
99
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"5e-07"
,
0
.
00000050000005
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.100469"
,
0
.
100469499
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1"
,
0
.
9999995
f
);
/*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1"
,
1
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.25"
,
1
.
25
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"7.99999"
,
7
.
99999
f
);
/*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.0002"
,
16
.
0002
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.0004"
,
16
.
0004
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.0006"
,
16
.
0006
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"999999"
,
999999
.
0
f
);
/*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0"
,
-
0
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.99e-07"
,
-
0
.
0000004
99
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-5e-07"
,
-
0
.
00000050000005
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.100469"
,
-
0
.
100469499
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1"
,
-
0
.
9999995
f
);
/*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1"
,
-
1
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1.25"
,
-
1
.
25
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-7.99999"
,
-
7
.
99999
f
);
/*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.0002"
,
-
16
.
0002
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.0004"
,
-
16
.
0004
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.0006"
,
-
16
.
0006
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-999999"
,
-
999999
.
0
f
);
/*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.29497e+09"
,
4294967296
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"5e+09"
,
5000000000
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"8e+09"
,
8.0e+09
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"8.31e+09"
,
8309999104
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1e+10"
,
1.0e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1e+10"
,
10000000000
.
0
f
);
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_INCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0"
,
0
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.99e-07"
,
0
.
0000004
99
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.1004695"
,
0
.
100469499
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"2"
,
1
.
9999995
f
);
/*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1"
,
1
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.25"
,
1
.
25
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"7.999999"
,
7
.
999999
f
);
/*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.00002"
,
16
.
00002
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.00004"
,
16
.
00004
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.00006"
,
16
.
00006
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9999999"
,
9999999
.
0
f
);
/*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0"
,
-
0
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.99e-07"
,
-
0
.
0000004
99
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.1004695"
,
-
0
.
100469499
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-2"
,
-
1
.
9999995
f
);
/*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1"
,
-
1
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1.25"
,
-
1
.
25
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-7.999999"
,
-
7
.
999999
f
);
/*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.00002"
,
-
16
.
00002
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.00004"
,
-
16
.
00004
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.00006"
,
-
16
.
00006
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-9999999"
,
-
9999999
.
0
f
);
/*Last full print integer*/
/* Fails, prints "4.294968e+09" due to FP math imprecision
* TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967296.0f); */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"5e+09"
,
5000000000
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"8e+09"
,
8.0e+09
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"8.309999e+09"
,
8309999104
.
0
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1e+10"
,
1.0e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1e+10"
,
10000000000
.
0
f
);
/* Some compilers have trouble with inexact float constants, a float cast works generally */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.00005e+10"
,
(
float
)
1.000054e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.1e+38"
,
(
float
)
1.10000005e+38
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.6353e+10"
,
1.63529943e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"3.40282e+38"
,
3.40282346638e38
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.000055e+10"
,
(
float
)
1.000055e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.1e+38"
,
(
float
)
1.10000005e+38
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.635299e+10"
,
1.63529943e+10
f
);
/* Fails, prints "3.402824e+38" due to FP math imprecision
* TEST_ASSERT_EQUAL_PRINT_FLOATING("3.402823e+38", 3.40282346638e38f); */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1e+10"
,
-
1.0e+10
f
);
/* Fails, prints "-3.402824e+38" due to FP math imprecision
* TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.402823e+38", -3.40282346638e38f); */
#endif
}
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1e+10"
,
-
1.0e+10
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-3.40282e+38"
,
-
3.40282346638e38
f
);
void
testFloatPrintingRoundTiesToEven
(
void
)
{
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_INCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.0004882813"
,
0
.
0004
8828125
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"488281.3"
,
488281
.
25
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"5.000001e-07"
,
0
.
00000050000005
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-5.000001e-07"
,
-
0
.
00000050000005
f
);
#else
/* Default to Round ties to even */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.0004882812"
,
0
.
0004
8828125
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"488281.2"
,
488281
.
25
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"5e-07"
,
0
.
00000050000005
f
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-5e-07"
,
-
0
.
00000050000005
f
);
#endif
#endif
}
...
...
@@ -4556,37 +4576,84 @@ void testFloatPrintingInfinityAndNaN(void)
}
#if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY)
#ifdef UNITY_INCLUDE_DOUBLE
static
void
printFloatValue
(
float
f
)
{
char
expected
[
18
];
startPutcharSpy
();
UnityPrintFloat
(
f
);
sprintf
(
expected
,
"%.9g"
,
f
);
/* We print all NaN's as "nan", not "-nan" */
if
(
strcmp
(
expected
,
"-nan"
)
==
0
)
strcpy
(
expected
,
"nan"
);
if
(
strcmp
(
expected
,
getBufferPutcharSpy
()))
{
/* Fail with diagnostic printing */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
expected
,
f
);
}
}
#else
static
void
printFloatValue
(
float
f
)
{
char
expected
[
18
];
char
expected_lower
[
18
];
char
expected_lower2
[
18
];
char
expected_lower3
[
18
];
char
expected_higher
[
18
];
char
expected_higher2
[
18
];
char
expected_higher3
[
18
];
startPutcharSpy
();
UnityPrintFloat
(
f
);
sprintf
(
expected
,
"%.6g"
,
f
);
sprintf
(
expected
,
"%.7g"
,
f
);
/* We print all NaN's as "nan", not "-nan" */
if
(
strcmp
(
expected
,
"-nan"
)
==
0
)
strcpy
(
expected
,
"nan"
);
if
(
strcmp
(
expected
,
"-nan"
)
==
0
)
strcpy
(
expected
,
"nan"
);
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 last digit */
double
lower
=
(
double
)
f
*
0
.
9999995
;
double
higher
=
(
double
)
f
*
1
.
0000005
;
/* Allow for rounding differences in
the
last digit */
double
lower
=
(
double
)
f
*
0
.
999999
9
5
;
double
higher
=
(
double
)
f
*
1
.
000000
0
5
;
if
(
isfinite
(
lower
))
sprintf
(
expected_lower
,
"%.6g"
,
lower
);
else
strcpy
(
expected_lower
,
expected
);
if
(
isfinite
(
higher
))
sprintf
(
expected_higher
,
"%.6g"
,
higher
);
else
strcpy
(
expected_higher
,
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
&&
strcmp
(
expected_higher
,
getBufferPutcharSpy
())
!=
0
)
strcmp
(
expected_lower2
,
getBufferPutcharSpy
())
!=
0
&&
strcmp
(
expected_lower3
,
getBufferPutcharSpy
())
!=
0
&&
strcmp
(
expected_higher
,
getBufferPutcharSpy
())
!=
0
&&
strcmp
(
expected_higher2
,
getBufferPutcharSpy
())
!=
0
&&
strcmp
(
expected_higher3
,
getBufferPutcharSpy
())
!=
0
)
{
/* Fail with diagnostic printing */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
expected
,
f
);
}
}
#endif
#endif
void
testFloatPrintingRandomSamples
(
void
)
{
...
...
@@ -5286,20 +5353,60 @@ void testDoublePrinting(void)
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.100469"
,
0
.
10046949999999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.29497e+09"
,
4294967295
.
999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.29497e+09"
,
4294967295
.
9999995
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.29497e+09"
,
4294967296
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1e+10"
,
9999999995
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.0072e+15"
,
9007199254740990
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"7e+100"
,
7.0e+100
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"3e+200"
,
3.0e+200
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.23457e+300"
,
9.23456789e+300
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.100469"
,
-
0
.
10046949999999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.29497e+09"
,
-
4294967295
.
999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.29497e+09"
,
-
4294967295
.
9999995
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-7e+100"
,
-
7.0e+100
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0"
,
0
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.99e-07"
,
0
.
0000004
99
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"5.0000005e-07"
,
0
.
00000050000005
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.100469499"
,
0
.
100469499
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1"
,
0
.
9999999995
);
/*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1"
,
1
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.25"
,
1
.
25
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"7.99999999"
,
7
.
99999999
);
/*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.0000002"
,
16
.
0000002
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.0000004"
,
16
.
0000004
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"16.0000006"
,
16
.
0000006
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"999999999"
,
999999999
.
0
);
/*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0"
,
-
0
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.99e-07"
,
-
0
.
0000004
99
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-5.0000005e-07"
,
-
0
.
00000050000005
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.100469499"
,
-
0
.
100469499
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1"
,
-
0
.
9999999995
);
/*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1"
,
-
1
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-1.25"
,
-
1
.
25
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-7.99999999"
,
-
7
.
99999999
);
/*Not rounding*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.0000002"
,
-
16
.
0000002
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.0000004"
,
-
16
.
0000004
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-16.0000006"
,
-
16
.
0000006
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-999999999"
,
-
999999999
.
0
);
/*Last full print integer*/
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"0.1004695"
,
0
.
10046949999999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.2949673e+09"
,
4294967295
.
9
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"4.2949673e+09"
,
4294967296
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1e+10"
,
9999999995
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719925e+15"
,
9007199254740990
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"7e+100"
,
7.0e+100
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"3e+200"
,
3.0e+200
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.23456789e+300"
,
9.23456789e+300
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-0.1004695"
,
-
0
.
10046949999999999
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.2949673e+09"
,
-
4294967295
.
9
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-4.2949673e+09"
,
-
4294967296
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"-7e+100"
,
-
7.0e+100
);
#endif
}
void
testDoublePrintingRoundTiesToEven
(
void
)
{
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
TEST_IGNORE
();
#else
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1.00000001e+10"
,
10000000050
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719925e+15"
,
9007199245000000
.
0
);
#else
/* Default to Round ties to even */
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"1e+10"
,
10000000050
.
0
);
TEST_ASSERT_EQUAL_PRINT_FLOATING
(
"9.00719924e+15"
,
9007199245000000
.
0
);
#endif
#endif
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录