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

Unnecessary floating point support?

Hi,

My problem is that I have integer constants coded as compile-time constant floating equations to avoid having to use the floating point library... let me explain...

Take some code that does not use floating point operations - say:

void main(void)
{
   unsigned int i = 1000;
   for (; i; i--)
     ;
}

Under Projects / Options / C/C++ / Misc Controls: add the directive:

--fpu=none

since we don't need FPU support.

Like this, the program will compile.

Now, ask the compiler to do some compile-time floating-point calculation that results in an integer - insert at head of file:

unsigned int j = (unsigned int)(1.0*3.0);

The RealView compiler refuses to compile the line, even though we don't need FP support at run-time.

Is there a way round this?

Parents

  • #define DAC_const       (15.0/255)
    #define VPP_5V          (BYTE)((5.0/DAC_const)+0.5)
    #define VPP_12V         (BYTE)((12.0/DAC_const)+0.5)
    #define VPP_OFF         (BYTE)((0.0/DAC_const)+0.5
    
    

    Because of this limitation, the code has to be written:

    #define VPP_5V                     (BYTE)(85U)
    #define VPP_12V                 (BYTE)(204U)
    #define VPP_OFF                 (BYTE)(0U)
    
    



    which is not as good.

    If you changed the definitions to the following they would be the same as the floating point versions

    #define VPP_5V (BYTE)(86U) //(BYTE)((5.0/DAC_const)+0.5) evaluates to 86 not 85
    #define VPP_12V (BYTE) (205U)
    #define VPP_OFF (BYTE) (1U)
    
    #define ONE_OVER_DAC_CONSTANT (17U)
    
    // Because 1 / DAC_const is an exact integer (17) , you could do 5 * 17 and just add 1 because you are rounding up.
    
    
    

Reply

  • #define DAC_const       (15.0/255)
    #define VPP_5V          (BYTE)((5.0/DAC_const)+0.5)
    #define VPP_12V         (BYTE)((12.0/DAC_const)+0.5)
    #define VPP_OFF         (BYTE)((0.0/DAC_const)+0.5
    
    

    Because of this limitation, the code has to be written:

    #define VPP_5V                     (BYTE)(85U)
    #define VPP_12V                 (BYTE)(204U)
    #define VPP_OFF                 (BYTE)(0U)
    
    



    which is not as good.

    If you changed the definitions to the following they would be the same as the floating point versions

    #define VPP_5V (BYTE)(86U) //(BYTE)((5.0/DAC_const)+0.5) evaluates to 86 not 85
    #define VPP_12V (BYTE) (205U)
    #define VPP_OFF (BYTE) (1U)
    
    #define ONE_OVER_DAC_CONSTANT (17U)
    
    // Because 1 / DAC_const is an exact integer (17) , you could do 5 * 17 and just add 1 because you are rounding up.
    
    
    

Children