1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-23 00:15:58 +01:00

Round ties to even by default, many C libraries follow this

Linux gcc & clang and OSX clang produce output with ties round to even
Windows mingw gcc does not
Example 0.0078125 prints '0.007812'
This commit is contained in:
jsalling
2016-11-09 23:07:31 -06:00
parent 4a27d14734
commit 54fe786fae
2 changed files with 11 additions and 0 deletions

View File

@@ -3243,6 +3243,8 @@ void testFloatVerbosePrinting(void)
float smallest = 0.0000005f;
*(int*)&smallest += 1;
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.000001", smallest);
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.007812", 0.0078125f); /*not if ties round away from 0*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.976562", 0.9765625f); /*not if ties round away from 0*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.100469499f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0", 0.9999995f); /*Rounding to int place*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0", 1.0f);
@@ -3259,6 +3261,7 @@ void testFloatVerbosePrinting(void)
TEST_ASSERT_EQUAL_PRINT_FLOATING("8.3099991e+09", 8309999104.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 1.0e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 10000000000.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00005499e+10", 1.000055e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.10000006e+38", 1.10000005e+38f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.63529943e+10", 1.63529943e+10f);
@@ -3275,6 +3278,9 @@ void testFloatVerbosePrinting(void)
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967295.9999995);
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 9999999995.0);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 10000000050.0); /*not if ties round away from 0*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719924e+15", 9007199245000000.0); /*not if ties round away from 0*/
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199254740990.0);
TEST_ASSERT_EQUAL_PRINT_FLOATING("7.0e+100", 7.0e+100);
TEST_ASSERT_EQUAL_PRINT_FLOATING("Inf", 1.7976931348623157e308*10.0);