From d0da273ffc387e31f42cf578d86566907edec0ed Mon Sep 17 00:00:00 2001 From: Dennis Sperzel Date: Wed, 7 Feb 2024 10:32:47 +0100 Subject: [PATCH] testing: addition reading precision out of double numbers --- test/test_addition.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test_addition.c b/test/test_addition.c index ad81d17..7456ef4 100644 --- a/test/test_addition.c +++ b/test/test_addition.c @@ -297,4 +297,23 @@ void test_addition_sign_double_numbers(void) TEST_ASSERT_EQUAL_UINT64(expected[1], result[1]); } +void test_addition_precision_double_numbers(void) +{ + unsigned long long result[5]; + numberd[0].dnum = 3216752.2348648931012, numberd[1].dnum = -79865431546, numberd[2].dnum = 203, numberd[3].dnum = -0.00460023540056432002, numberd[4].dnum = 0.000000000791340265431213; + unsigned long long expected[5] = { (numberd[0].lnum << 12) >> 12 , (numberd[1].lnum << 12) >> 12, (numberd[2].lnum << 12) >> 12, (numberd[3].lnum << 12) >> 12, (numberd[4].lnum << 12) >> 12}; + + result[0] = precision_double( numberd[0].lnum ); + result[1] = precision_double( numberd[1].lnum ); + result[2] = precision_double( numberd[2].lnum ); + result[3] = precision_double( numberd[3].lnum ); + result[4] = precision_double( numberd[4].lnum ); + + TEST_ASSERT_EQUAL_UINT64(expected[0], result[0]); + TEST_ASSERT_EQUAL_UINT64(expected[1], result[1]); + TEST_ASSERT_EQUAL_UINT64(expected[2], result[2]); + TEST_ASSERT_EQUAL_UINT64(expected[3], result[3]); + TEST_ASSERT_EQUAL_UINT64(expected[4], result[4]); +} + #endif // TEST