From 2a6e61d44f94b7aca627f0aa5880ec7cfe3c7a77 Mon Sep 17 00:00:00 2001 From: Dennis Sperzel Date: Wed, 7 Feb 2024 10:51:47 +0100 Subject: [PATCH] refactoring: write numbers for bit operartions in hex for better readability --- src/addition.c | 13 ++++++------- test/test_addition.c | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/addition.c b/src/addition.c index 208161a..2db8d35 100644 --- a/src/addition.c +++ b/src/addition.c @@ -60,14 +60,14 @@ unsigned int sign_float(unsigned int number) { // reading precision out of an integer (floating number) unsigned int precision_float(unsigned int number) { - unsigned int precision = 8388607; + unsigned int precision = 0x007fffff; return (number & precision); } // reading exponent out of an integer (floating number) unsigned int exponent_float(unsigned int number) { - unsigned int exponent = 2139095040; + unsigned int exponent = 0x7f800000; return (number & exponent) >> 23; } @@ -90,7 +90,7 @@ float addition_float(float number1, float number2) { else if (number1 == (float) 0.0) return number2; else if (number2 > number1) return addition_float(number2, number1); - unsigned int e = 8388608; + unsigned int e = 0x00800000; struct data num1, num2, num3; num1.number.floating = number1, num2.number.floating = number2; num1.sign = sign_float(num1.number.integer), num2.sign = sign_float(num2.number.integer); @@ -98,7 +98,7 @@ float addition_float(float number1, float number2) { num1.precision = precision_float(num1.number.integer) | e, num2.precision = precision_float(num2.number.integer) | e; num3.precision = addition_precision_float(num1.precision, num2.precision >> (num1.exponent - num2.exponent)); - if (num3.precision > 16777215) { + if (num3.precision > 0x00ffffff) { num3.exponent = addition_uint(num1.exponent, 1); num3.precision = (num3.precision >> 1); } @@ -112,11 +112,10 @@ float addition_float(float number1, float number2) { } unsigned long long sign_double(unsigned long long a) { - if (a & 0x8000000000000000 == 0x8000000000000000) return 1; + if (a & 0x8000000000000000) return 1; else return 0; } unsigned long long precision_double(unsigned long long a) { - a &= 0x000fffffffffffff; - return a; + return a & 0x000fffffffffffff; } \ No newline at end of file diff --git a/test/test_addition.c b/test/test_addition.c index 7456ef4..08b668b 100644 --- a/test/test_addition.c +++ b/test/test_addition.c @@ -6,7 +6,7 @@ num carry[1]; -unsigned int e = 8388608; +unsigned int e = 0x00800000; union { float floating;