|
@ -9,9 +9,9 @@ struct data |
|
|
float floating; |
|
|
float floating; |
|
|
unsigned int integer; |
|
|
unsigned int integer; |
|
|
} number; |
|
|
} number; |
|
|
unsigned int s; |
|
|
|
|
|
unsigned int e; |
|
|
|
|
|
unsigned int p; |
|
|
|
|
|
|
|
|
unsigned int sign; |
|
|
|
|
|
unsigned int exponent; |
|
|
|
|
|
unsigned int precision; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// full_adder is an implementation of two bit addition with carry |
|
|
// full_adder is an implementation of two bit addition with carry |
|
@ -83,20 +83,20 @@ float addition_float(float number1, float number2) { |
|
|
unsigned int e = 8388608; |
|
|
unsigned int e = 8388608; |
|
|
struct data num1, num2, num3; |
|
|
struct data num1, num2, num3; |
|
|
num1.number.floating = number1, num2.number.floating = number2; |
|
|
num1.number.floating = number1, num2.number.floating = number2; |
|
|
num1.s = sign(num1.number.integer), num2.s = sign(num2.number.integer); |
|
|
|
|
|
num1.e = exponent(num1.number.integer), num2.e = exponent(num2.number.integer); |
|
|
|
|
|
num1.p = precision(num1.number.integer) | e, num2.p = precision(num2.number.integer) | e; |
|
|
|
|
|
|
|
|
|
|
|
num3.p = addition_precision(num1.p, num2.p >> (num1.e - num2.e)); |
|
|
|
|
|
if (num3.p > 16777215) { |
|
|
|
|
|
num3.e = addition(num1.e, 1); |
|
|
|
|
|
num3.p = (num3.p >> 1); |
|
|
|
|
|
|
|
|
num1.sign = sign(num1.number.integer), num2.sign = sign(num2.number.integer); |
|
|
|
|
|
num1.exponent = exponent(num1.number.integer), num2.exponent = exponent(num2.number.integer); |
|
|
|
|
|
num1.precision = precision(num1.number.integer) | e, num2.precision = precision(num2.number.integer) | e; |
|
|
|
|
|
|
|
|
|
|
|
num3.precision = addition_precision(num1.precision, num2.precision >> (num1.exponent - num2.exponent)); |
|
|
|
|
|
if (num3.precision > 16777215) { |
|
|
|
|
|
num3.exponent = addition(num1.exponent, 1); |
|
|
|
|
|
num3.precision = (num3.precision >> 1); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
num3.e = num1.e; |
|
|
|
|
|
|
|
|
num3.exponent = num1.exponent; |
|
|
} |
|
|
} |
|
|
num3.p ^= e; |
|
|
|
|
|
num3.number.integer = output(num1.s, num3.e, num3.p); |
|
|
|
|
|
|
|
|
num3.precision ^= e; |
|
|
|
|
|
num3.number.integer = output(num1.sign, num3.exponent, num3.precision); |
|
|
|
|
|
|
|
|
return num3.number.floating; |
|
|
return num3.number.floating; |
|
|
} |
|
|
} |