From 1f296acd8707018872227d7c8ffa22f74291ac1d Mon Sep 17 00:00:00 2001 From: Dennis Sperzel Date: Mon, 5 Feb 2024 11:47:57 +0100 Subject: [PATCH] testing: addition read precision of a floating number --- test/test_addition.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test_addition.c b/test/test_addition.c index 0d97725..85143ac 100644 --- a/test/test_addition.c +++ b/test/test_addition.c @@ -6,6 +6,11 @@ num carry[1]; +union { + float f; + unsigned int i; +} a[5]; + void setUp(void) { } @@ -151,6 +156,24 @@ void test_addition_signnumber(void) { TEST_ASSERT_EQUAL_UINT(expected[1], result[1]); } +void test_addition_precisionfloatingnumber(void) { + unsigned int result[5]; + a[0].f = 0, a[1].f = -34753168, a[2].f = 75613594, a[3].f = -0.00000044568721, a[4].f = 0.0000004796123; + unsigned int expected[5] = { ( a[0].i << 9) >> 9 , ( a[1].i << 9) >> 9, ( a[2].i << 9) >> 9, ( a[3].i << 9) >> 9, ( a[4].i << 9) >> 9}; + + result[0] = m( a[0].i ); + result[1] = m( a[1].i ); + result[2] = m( a[2].i ); + result[3] = m( a[3].i ); + result[4] = m( a[4].i ); + + TEST_ASSERT_EQUAL_UINT(expected[0], result[0]); + TEST_ASSERT_EQUAL_UINT(expected[1], result[1]); + TEST_ASSERT_EQUAL_UINT(expected[2], result[2]); + TEST_ASSERT_EQUAL_UINT(expected[3], result[3]); + TEST_ASSERT_EQUAL_UINT(expected[4], result[4]); +} + void test_addition_addition_float_0plus0gleich0(void) { float result; float expected = 0.0;