I haven't done a lot of floating point math programming in any language let alone in C.
I'm writing a temperature conversion program as an exercise and have a question about floating point numbers. I have a code frag as listed below. In both cases Temp1 and Temp2 are 0.0 when P_FahrenheitTemp is <> 32.0. However, if I use the CF3 factor in the calculation the LOC VERRKKKS!!! :-)
This seems intuitively obvious to me but... Is this compiler dependent or is a cast operator necessary on the initialization? BTW, I'm writing this code on an IBM iSeries platform using the C/C++ compiler which strictly adheres to ASNI and ISO standards.
Thank you in advance for any info!
Martin Kuester
#define CF3 5/9;
float Conv2Celsius(float P_FahrenheitTemp)
{
float Temp1, Temp2, Temp3;
float ConvAdj = 32.0;
float CF1 = 0.555556;
float CF2 = 5/9;
//[°C] = ([°F] - 32) × 5/9
Temp1 = (P_FahrenheitTemp - ConvAdj) * CF1;
Temp2 = (P_FahrenheitTemp - ConvAdj) * CF2;
Temp3 = (P_FahrenheitTemp - ConvAdj) * CF3;
return(Temperature);
}