get wrong return value of float of a function

11 Views Asked by At

I have a function that calculate multiplication two float numbers in FPU representation(sign,exponent,mantissa).The output of the multiplication function is correct in print but when I get the return value of the function in another function it get wrong value. the main function is in another file at same project.

Here is code:

float fpu(double x,double y)
{

myfloat var1;
myfloat var2;
var1.f = x;
var2.f = y;
float g= var1.f * var2.f;
float ft= exploitdata(var1,var2,g);
printf("\n final number is : %f",ft);
return ft;
}
int main()
{

 float w=0;
 w=fpu(0.285,-0.2574);
 printf("\n output is: %f",w);
 return 0;
}

and output is :

final number is: -0.073359
output is : 29.00000

I try double and printf("%lf") but it steel get wrong value.I change the type of function to double fpu(double x,double y) but it could't help.

0

There are 0 best solutions below