diff --git a/src/addition.c b/src/addition.c index 5dcd167..e898b9f 100644 --- a/src/addition.c +++ b/src/addition.c @@ -19,9 +19,9 @@ struct datad { double dnum; unsigned long long lnum; } number; - unsigned long sign; - unsigned long exponent; - unsigned long precision; + unsigned long long sign; + unsigned long long exponent; + unsigned long long precision; }; // full_adder is an implementation of two bit addition with carry @@ -97,7 +97,8 @@ float addition_float(float number1, float number2) { num1.exponent = exponent_float(num1.number.integer), num2.exponent = exponent_float(num2.number.integer); 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)); + unsigned int k = (num1.exponent - num2.exponent > 23 ? 24 : num1.exponent - num2.exponent); + num3.precision = addition_precision_float(num1.precision, num2.precision >> k ); if (num3.precision > 0x00ffffff) { num3.exponent = addition_uint(num1.exponent, 1); num3.precision = (num3.precision >> 1); @@ -135,4 +136,12 @@ unsigned long long exponent_double(unsigned long long number) { unsigned long long output_double(unsigned long long sign, unsigned long long exponent, unsigned long long precision) { return (sign << 63) | (exponent << 52) | precision; +} + +// adding two precision together + +unsigned long long addition_precision_double(unsigned long long p1, unsigned long long p2) { + unsigned long long hinten = 0x00000000ffffffff; + unsigned int vornep1 = p1 >> 32, hintenp1 = p1 & hinten, vornep2 = p2 >> 32, hintenp2 = p2 & hinten; + return ((unsigned long long) addition_uint(vornep1, vornep2) << 32) + (unsigned long long) addition_uint(hintenp1, hintenp2); } \ No newline at end of file diff --git a/src/addition.h b/src/addition.h index 0ed5aec..e04231e 100644 --- a/src/addition.h +++ b/src/addition.h @@ -31,4 +31,6 @@ unsigned long long exponent_double(unsigned long long number); unsigned long long output_double(unsigned long long sign, unsigned long long exponent, unsigned long long precision); +unsigned long long addition_precision_double(unsigned long long p1, unsigned long long p2); + #endif // ADDITION_H \ No newline at end of file diff --git a/test/test_addition.c b/test/test_addition.c index 225882a..642842c 100644 --- a/test/test_addition.c +++ b/test/test_addition.c @@ -8,6 +8,8 @@ num carry[1]; unsigned int e = 0x00800000; +unsigned long long ed = 0x0010000000000000; + union { float floating; unsigned int integer;