C/C++ >> Floating point number problems
Posted by dxprog on 13:06:00 05-27-2003
I am having problems with floating point operations in that they always seem to turn out 0. Here's my code:
/* values */
tw = 400;
th = 100;
x = 0;
y = 0;
height = 100;
width = 100;

float tx1 = ((1 / tw) * x) / 10;
float tw1 = (tx1 + ((1 / tw) * width)) / 10;
float ty1 = ((1 / th) * y) / 10;
float th1 = (ty1 + ((1 / th) * height)) / 10;

Somehow or other all these values are zip. To find out the values of these I am writing them to a file with the following code:

FILE *stream;
stream = fopen("c:\\eat debug.txt", "w");
fprintf(stream, "%f\n%f\n%f\n%f", tx1, tw1, ty1, th1);
fclose(stream);

Is my problem in the numbers or in the debug output. Thanks for any help. [addsig]
Posted by dxprog on 02:37:00 05-28-2003
Found out the problem. I was using integers the equation (keep forgetting that there is no automatic type conversion in C) [addsig]