Browse Source

refactoring: write numbers for bit operartions in hex for better readability

master
Dennis Sperzel 11 months ago
parent
commit
2a6e61d44f
  1. 13
      src/addition.c
  2. 2
      test/test_addition.c

13
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;
}

2
test/test_addition.c

@ -6,7 +6,7 @@
num carry[1];
unsigned int e = 8388608;
unsigned int e = 0x00800000;
union {
float floating;

Loading…
Cancel
Save