diff --git a/src/addition.c b/src/addition.c index afa0ea4..724dd99 100644 --- a/src/addition.c +++ b/src/addition.c @@ -1,12 +1,16 @@ #include "addition.h" #include +// full_adder is an implementation of two bit addition with carry + void full_adder (num* sum, num* nextcarry, num number1, num number2, num carry) { sum[0] = (number1 % 2) ^ (number2 % 2) ^ (carry % 2); nextcarry[0] = ((number1 % 2) & (number2 % 2)) | ((number1 % 2) & (carry % 2)) | ((number2 % 2) & (carry % 2)); } +// addition is an implementation of an 32 bit addition + unsigned int addition(num number1, num number2) { unsigned int result = 0; num sum[1] = {0}; @@ -24,15 +28,21 @@ unsigned int addition(num number1, num number2) { return result; } -unsigned int s(unsigned int a) { - return a >> 31; +// reading sign out of an integer (floating number) + +unsigned int sign(unsigned int number) { + return number >> 31; } -unsigned int m(unsigned int a) { - unsigned int num = 8388607; - return (a & num); +// reading precision out of an integer (floating number) + +unsigned int precision(unsigned int number) { + unsigned int precision = 8388607; + return (number & precision); } -float addition_float(float a, float b) { +// addition of two floating numbers + +float addition_float(float number1, float number2) { return 0.0; } \ No newline at end of file diff --git a/src/addition.h b/src/addition.h index 66497e0..cf09c60 100644 --- a/src/addition.h +++ b/src/addition.h @@ -5,12 +5,12 @@ typedef unsigned int num; void full_adder (num* sum, num* nextcarry, num number1, num number2, num carry); -unsigned int addition(num a, num b); +unsigned int addition(num number1, num number2); -unsigned int s(unsigned int a); +unsigned int sign(unsigned int number); -unsigned int m(unsigned int a); +unsigned int precision(unsigned int number); -float addition_float(float a, float b); +float addition_float(float number1, float number2); #endif // ADDITION_H diff --git a/test/test_addition.c b/test/test_addition.c index 0b3058a..2f68711 100644 --- a/test/test_addition.c +++ b/test/test_addition.c @@ -143,8 +143,8 @@ void test_addition_signfloatingnumber(void) { unsigned int expected[2] = { 0, 1 }; number[0].floating = 1, number[1].floating = -1; - result[0] = s(number[0].integer); - result[1] = s(number[1].integer); + result[0] = sign(number[0].integer); + result[1] = sign(number[1].integer); TEST_ASSERT_EQUAL_UINT(expected[0], result[0]); TEST_ASSERT_EQUAL_UINT(expected[1], result[1]); @@ -155,11 +155,11 @@ void test_addition_precisionfloatingnumber(void) { number[0].floating = 0, number[1].floating = -34753168, number[2].floating = 75613594, number[3].floating = -0.00000044568721, number[4].floating = 0.0000004796123; unsigned int expected[5] = { ( number[0].integer << 9) >> 9 , ( number[1].integer << 9) >> 9, ( number[2].integer << 9) >> 9, ( number[3].integer << 9) >> 9, ( number[4].integer << 9) >> 9}; - result[0] = m( number[0].integer ); - result[1] = m( number[1].integer ); - result[2] = m( number[2].integer ); - result[3] = m( number[3].integer ); - result[4] = m( number[4].integer ); + result[0] = precision( number[0].integer ); + result[1] = precision( number[1].integer ); + result[2] = precision( number[2].integer ); + result[3] = precision( number[3].integer ); + result[4] = precision( number[4].integer ); TEST_ASSERT_EQUAL_UINT(expected[0], result[0]); TEST_ASSERT_EQUAL_UINT(expected[1], result[1]);