This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Double vs. single precision for C6748

Hello,

Background:

We are migrating an application from windows console to C6748. We have made some good progess, but are now running through a computationally intensive portion. The memory requirements are quite large and one area we are trying to "economize" in is the use of floats instead of doubles.

We are seeing some data values drifting potentially as a result of the lower precision 32-bit float or possibly for other reasons:

The program uses a number of standard calls to functions like "floor", "ceil", "sin", "cos"...etc. From what I can see the standard math.h include specifies all those functions as doubles. We are passing and accepting all  values as floats. The compiler and linker don't seem to be upset about this, but I noticed that there is the equivalent library for floats (mathf.h) available with all functions defined with an "f" afterwards.

Should I be changing all the functions to the "f" extension version or is the compiler already re-directing to the float versions and hence does not complain? The values returned are often not unreasonable and so it is not obvious what is happening.

Thanks in advance for any help.

Dan.

 

 

  • The compiled code converts those floats to doubles, calls the math.h function, the computation is done in double, a double is returned, then that result is converted to float.  If you want it all done in float, you have to explicitly change to the float version of the function.  Such a change is not done automatically.  Track your code size carefully as you make this change.  My guess is that you won't save that much.  But you don't know until you try.

    Thanks and regards,

    -George

  • DanB said:

    The values returned are often not unreasonable and so it is not obvious what is happening.

    I've got to ask: do you have a case where a float library function returns an unreasonable value?

  • Hi George,

    OK...Thanks for confirming that.

    No I don't have any issues with having an automatic conversion to double occurring so I will probably leave it the way it is.

     

    Thanks for your help.

     

    Dan.

     

  • Hi,

    No.. I was just being "funny"... I would imagine that a true direct-conversion of float to double (i.e. not actually converting it and adding extra bytes) would produce something very ugly indeed! The only way we would have got something truely unresaonable would be through our own fault!

     

    Thanks for asking though.

     

    Dan.