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.

Float compared to a const double sometimes fails?

Other Parts Discussed in Thread: OMAP-L138

Take the following code example.  osu_max_F32 is a wrapper for fmaxf.  (Using an OMAP-L138, this is code compiled for the ARM9).

test_number = osu_max_F32(35.0, 30.0);

snprintf(Str, MAXSTRING - 1,"Valid: osu_max_F32(35.0,30.0) = %llf", test_number);

status[0] = (test_number > 34.9) ? TRUE : FALSE;

status[1] = (test_number < 35.1) ? TRUE : FALSE;

RValue = result(Str,(status[0] && status[1]), pEb,2);

 

Status[0] get a 1 like it should but status[1] gets a 0.  Looking at the assembly code test_number gets converted to a double like I would expect but the comparison fails.

That shouldn't happen right or what am I missing?  Please enlighten me.

If I change the constants to have "F" behind them (35.1F) it works.
 

  • I cannot reproduce this problem.  Please post a compilable test case that demonstrates the problem.  Please include the command-line options used and the compiler version (not the CCS version).

    Note that %llf is not a valid printf conversion; you should use %f for float or double, and %Lf for long double.

  • Note that I added the Double to see if it was the conversion or the comparison that was the issue.  It seems to do the conversion correctly but the comparison is the issue.

    void test_double_fail (void)

    {

    float test_number;

    double Double;

    xdc_Bool status[2];

    test_number = fmaxf(35.0,30.0);

    status[0] = (test_number > 34.9) ? TRUE : FALSE;

    status[1] = (test_number < 35.1) ? TRUE : FALSE;

    Double = (double)test_number;

    if (status[0] && status[1]) {

    System_printf("Yeh!\n");

    } else {

    System_printf("Boooo!\n");

    }

    }

     

    C:\TI\ccsv5\utils\bin\gmake -k all

    'Building file: ../main.c'

    'Invoking: TMS470 Compiler'

    "C:/TI/ccsv5/tools/compiler/tms470/bin/cl470" -mv5e -g --fp_mode=strict --define=xdc__strict --include_path="C:/TI/ccsv5/tools/compiler/tms470/include" --include_path="C:/CCS/VSLED_Source_Code/Memory_Management/h" --include_path="C:/CCS/VSLED_Source_Code/misc/h" --include_path="C:/CCS/VSLED_Source_Code/OS_Utils/h" --include_path="C:/CCS/VSLED_Source_Code/Data_Bus/h" --diag_warning=225 --display_error_number -me --abi=eabi --code_state=32 --float_support=fpalib --printf_support=full --preproc_with_compile --preproc_dependency="main.pp" --cmd_file="./configPkg/compiler.opt" "../main.c"

    "../main.c", line 296: warning #190-D: enumerated type mixed with another type

    "../main.c", line 342: warning #190-D: enumerated type mixed with another type

    "../main.c", line 1083: warning #552-D: variable "Double" was set but never used

    "../main.c", line 1605: warning #552-D: variable "test_date" was set but never used

    "../main.c", line 1606: warning #552-D: variable "Mikie" was set but never used

    "../main.c", line 1703: warning #552-D: variable "RValue" was set but never used

    'Finished building: ../main.c'

    ' '

    'Building target: OS_Uils_PIT.out'

    'Invoking: TMS470 Linker'

    "C:/TI/ccsv5/tools/compiler/tms470/bin/cl470" -mv5e -g --fp_mode=strict --define=xdc__strict --diag_warning=225 --display_error_number -me --abi=eabi --code_state=32 --float_support=fpalib --printf_support=full -z -m"OS_Uils_PIT.map" --warn_sections -i"C:/TI/ccsv5/tools/compiler/tms470/lib" -i"C:/TI/ccsv5/tools/compiler/tms470/include" --reread_libs --rom_model -o "OS_Uils_PIT.out" -l"./configPkg/linker.cmd" "./main.obj" -l"libc.a" -l"C:\CCS\VSLED_Source_Code\OS_Utils\Debug\OS_Utils.lib" -l"C:\CCS\VSLED_Source_Code\Memory_Management\Debug\Memory_Management.lib"

    <Linking>

    'Finished building target: OS_Uils_PIT.out'

    ' '

    **** Build Finished ****

  • I am able to reproduce a bug, but it's not clear exactly where the problem is.  I've submitted SDSCM00044035 to track this issue.  If I can characterize it a little better, I'll post the details here.  In the meantime, what version of the compiler are you using (not the CCS version)?

  • I actually just downloaded the new version a few days ago...

    ARM Compiler Tools     4.9.4       com.ti.cgt.tms470.4.9.win32.feature.group              Texas Instruments

    Thanks,

     

  • Hmm, well, SDSCM00044035 isn't introduced until 5.0.0, so it must be something else.

    Did you remember to include math.h before calling fmaxf?  If this include is missing, your test case will fail.

  • Yes #include <math.h> is in the file.

    This function is put in a test file to test out a library of math functions that we need.  I have stepped through the assemble code and the fmaxf works fine.

  • I don't know why I was having trouble yesterday, but I have now reproduced a similar but distinct problem with 4.9.4.  I've submitted SDSCM00044038 to track this issue.

  • I have confirmed that a double compared to the const double seems to be the real issue.

     

    void test_double_fail (void)

    {

    float test_number;

    double Double;

    xdc_Bool status[2];

    test_number = fmaxf(35.0,30.0);

    status[0] = (test_number > 34.9) ? TRUE : FALSE;

    status[1] = (test_number < 35.1) ? TRUE : FALSE;

    Double = (double)test_number;

    if (status[0] && status[1]) {

    System_printf("Yeh!\n");

    } else {

    System_printf("Boooo!\n");

    }

    status[0] = (Double > 34.9) ? TRUE : FALSE;

    status[1] = (Double < 35.1) ? TRUE : FALSE;

    if (status[0] && status[1]) {

    System_printf("Yeh double!\n");

    } else {

    System_printf( "Boooo double!\n");

    }

    }

  • I have copied this code and run it on the DSP side of the OMAP-L138 and it seems to run fine there.  So the issue is only on the ARM side.

      C6000 Compiler Tools 7.3.5 com.ti.cgt.c6000.7.3.win32.feature.group Texas Instruments

      ARM Compiler Tools 4.9.4 com.ti.cgt.tms470.4.9.win32.feature.group Texas Instruments

     

  • The short answer is that using --float_support=fpalib is not supported with --abi=eabi.  Use --float_support=vfplib instead.  I'll have to defer a more detailed answer to someone who knows more about this issue.