This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Strange Float Behaviour

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

Parents
  • that assumes that the manual is written in language intelligible to the user...

    If someone has the skill to interpret "Unexpected end of file" as "Missing closing brace" then I shouldn't forsee much of a problem with a mere manual!

    Something that I do think is useful and Microsoft seem to be taking on board is adding a bit of helpful information to existing warnings/errors, so instead you get:

    C12345: Unexpected end of file (Possibly a closing brace is missing)

    or something similar. Now, there's progress.

Reply
  • that assumes that the manual is written in language intelligible to the user...

    If someone has the skill to interpret "Unexpected end of file" as "Missing closing brace" then I shouldn't forsee much of a problem with a mere manual!

    Something that I do think is useful and Microsoft seem to be taking on board is adding a bit of helpful information to existing warnings/errors, so instead you get:

    C12345: Unexpected end of file (Possibly a closing brace is missing)

    or something similar. Now, there's progress.

Children
  • "If someone has the skill to interpret "Unexpected end of file" as "Missing closing brace" then I shouldn't forsee much of a problem with a mere manual!"

    That'd be a trivial example.

    But trying to decipher what some of the arcane descriptions in the ISO spec actually mean is nigh-on impossible for mere mortals...

    "Something that I do think is useful and Microsoft seem to be taking on board is adding a bit of helpful information to existing warnings/errors"

    Keil made a start at this in C51 when you could press F1 on an error message a get a (hopefully) fuller description; eg,

    http://www.keil.com/support/man/docs/c51/c51_c101.htm

    Unfortunately, it's pretty half-baked and most of the "descriptions" are missing any really useful explanation.

    :-(

    The facility doesn't even exist at all in the ARM tools, as far as I can see.

    :-(

  • Unfortunately, it's pretty half-baked and most of the "descriptions" are missing any really useful explanation.

    Ach, Andy, I must agree and expand: Have you tried to look up details about linker errors/warnings for ARM chips at http://infocenter.arm.com?
    Oh, yeah.

  • i have had several experiences with so called "tech writers" and none have been pleasant.

    One blatant example was I wrote what I call a "manual template" ( a sketchy description) for a tech writer and one customer asked me a couple of questions and since there was a "personal report" I sent him a copy of the "manual template" an the customer called back "why did you not send that in the first place?"

    Erik

  • But trying to decipher what some of the arcane descriptions in the ISO spec actually mean is nigh-on impossible for mere mortals...

    Unfortunately it is an essential ability for an engineer.

    H+S is the next best thing and certainly presented in a more accessible formt.