Originally Posted by
megafiddle
Here is one problem:
Code:
E1=E2;
shift=E2-E1;
"shift" will always = 0
-
Hi.
Well I fixed it and it still returns wrong numbers. My main is this:
Code:
#include <stdio.h>
unsigned long add(unsigned long float1, unsigned long float2);
int main () {
unsigned long f1=6.5L, f2=0.6L, result;
result = add(f1,f2);
printf("%lu", result);
return 0;
}
unsigned long add(unsigned long float1, unsigned long float2) {
char E1=float1>>23, E2=float2>>23, E3=0;
unsigned long M1, M2, M3, M_mask=0x1, ofCheck=(0x1)<<24, res=0x0;
int shift;
M_mask=(M_mask<<24)-1;
M1=M_mask&float1;
M2=M_mask&float2;
if (E1<E2) { //aligning exponents and normalizing the Mantissas
shift=E2-E1;
E1=E2;
M1>>=shift;
}
else if (E2<E1) {
shift=E1-E2;
E2=E1;
M2>>=shift;
}
M3=M1+M2;
if (!(M3&ofCheck)) //checking overflow(24th bit) in mantissa
E3=E1;
else {
M3>>=1;
E3+=1;
}
res|=E3; //building the result
res<<=31;
res+=M3;
return res;
}
I would be glad if you or someone else can debug or run it and see what I mean.
Thanks