|
|
@ -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); |
|
|
|
} |