Tech Support banner

Status
Not open for further replies.
1 - 1 of 1 Posts

·
Registered
Joined
·
4 Posts
Discussion Starter #1
Hello,

I was trying to run a small program compiled with gcc 3.4.4 on cygwin. The program deals with floating point representation of numbers. I get wrong results when I try to print the long double variable: l_d_var.
I have pasted the code here:
#include <stdio.h>
#include <stdlib.h>
#define BOILING 212
main()
**
float f_var;
double d_var;
long double l_d_var = 0;

int i;
i = 0;
printf("Fahrenheit to Centigrade\n");
while(i <= BOILING)
**
fflush(stdout);
l_d_var = 5*(i-32);
printf("Value of long double first is: %lf\n",l_d_var);
l_d_var = l_d_var/9;
printf("Value of long double second is: %lf\n",l_d_var);
d_var = l_d_var;
printf("Value of d_var is: %f\n",d_var);

f_var = l_d_var;
printf("Value of f_var is: %f\n",f_var);
fflush(stdout);
printf("%d %f %f %lf\n", i, f_var, d_var, l_d_var);
i = i+1;
}
exit(EXIT_SUCCESS);
}


When I run the program after building it with gcc 3.4.4, I get the following result for i = 0:
Value of long double first is: -0.000000
Value of long double second is: -0.000000
Value of d_var is: -17.777778
Value of f_var is: -17.777779
0 -17.777779 -17.777778 -0.000000


The long double value is printed wrong for all values of i.
The calculation happens properly but when the long double value is printed, it is printed wrong. Why could this be happening?

Thanks and regards,
Smitha.
 
1 - 1 of 1 Posts
Status
Not open for further replies.
Top