Guys,
I am having a problem with float division using PK51. I was wondering if anyone could explain this or has seen it before.
I have a float, and want to divide it by 36000. If I do this directly, I get strange results, even -ve numbers although all the variables are +ve.
accrued_seconds =(total_accrued_seconds/36000);
Both variables are floats, however, if I do the following
accrued_seconds = (unsigned long)(total_accrued_seconds/10); accrued_hours = (float)(accrued_seconds/3600);
I get the correct result. For some reason that I don't understand using too big a divisor in the first code causes an error but not a two step as in the second. I have also tried the two step without the cast to an unsigned long and I get the errored result.
I tired the same thing on GCC on a PC and of course it works fine.
Any clues anyone?
Cheers,
Dirk
I'm not so sure. One of the purposes of standardisation is to provide you with a manual which, if followed to the letter, allows you to write code which should produce the result you expect. If the compiler translates that code in any way that does not conform to the standard it should issue a warning.
Your implicit trust of humans beings and their flawed abilities (evident in the forum, from time to time) is the most scary things about you, Jack.
"Your implicit trust of humans beings and their flawed abilities..."
It would be a terribly boring world if one didn't have trust.
Can't fly - Don't trust the pilot. Can't drive - Don't trust the EMU. Can't drink - Don't trust the bottling company.
etc
I have one more:
Jack Sprat: Can't program ? Don't trust the compiler... :-)
This must be too subtle for me. I don't implicitly trust human beings and/or their flawed abilities. You'll have to explain what you mean.