Abs function:- error: call of overloaded 'abs(float)' is ambiguous

Hi,

which #include can fix this error ?

(workspace) C:\workspace\Blinky3>yotta build
info: generate for target: stm32f429i-disco-gcc 0.0.20 at C:\workspace\Blinky3\yotta_targets\stm32f429i-disco-gcc
warning: subdirectory “test” of blinky3 0.0.0 at C:\workspace\Blinky3 was ignored because it doesn’t appear to contain any source files
GCC version is: 4.9.3
suppressing warnings from mbed-hal-st-stm32cubef4
– Configuring done
– Generating done
– Build files have been written to: C:/workspace/Blinky3/build/stm32f429i-disco-gcc
[2/3] Building CXX object source/CMakeFiles/blinky3.dir/C_/workspace/Blinky3/source/PreProcessor.cpp.o
FAILED: C:\yotta\gcc\bin\arm-none-eabi-g++.exe -DYOTTA_MODULE_NAME=blinky3 -Dblinky3_EXPORTS --std=gnu++11 -fno-exceptions -fno-unwind-tables -ffunction-sections -fdata-sections -Wall -Wextra -gstrict-dwarf -fno-rtti -fno-threadsafe-statics -mcpu=cortex-m4 -mthumb -D__thumb2__ -Os -g -gdwarf-3 -DNDEBUG -Igenerated/include -IC:/workspace/Blinky3 -IC:/workspace/Blinky3/yotta_modules/mbed-drivers -IC:/workspace/Blinky3/yotta_modules/cmsis-core-stm32f429xi -IC:/workspace/Blinky3/yotta_modules/mbed-hal -IC:/workspace/Blinky3/yotta_modules/cmsis-core -IC:/workspace/Blinky3/yotta_modules/ualloc -IC:/workspace/Blinky3/yotta_modules/minar -IC:/workspace/Blinky3/yotta_modules/core-util -IC:/workspace/Blinky3/yotta_modules/compiler-polyfill -IC:/workspace/Blinky3/yotta_modules/greentea-client -IC:/workspace/Blinky3/yotta_modules/mbed-hal-st -IC:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32f4 -IC:/workspace/Blinky3/yotta_modules/uvisor-lib -IC:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32cubef4 -IC:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32f429zi -IC:/workspace/Blinky3/yotta_modules/cmsis-core-st -IC:/workspace/Blinky3/yotta_modules/cmsis-core-stm32f4 -IC:/workspace/Blinky3/yotta_modules/dlmalloc -IC:/workspace/Blinky3/yotta_modules/minar-platform -IC:/workspace/Blinky3/yotta_modules/minar-platform-mbed -IC:/workspace/Blinky3/yotta_modules/mbed-drivers/mbed -IC:/workspace/Blinky3/yotta_modules/cmsis-core-stm32f429xi/cmsis-core-stm32f429xi -IC:/workspace/Blinky3/yotta_modules/mbed-hal/mbed-hal -IC:/workspace/Blinky3/yotta_modules/cmsis-core/cmsis-core -IC:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32f4/mbed-hal-st-stm32f4 -IC:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32cubef4/mbed-hal-st-stm32cubef4 -IC:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32f429zi/mbed-hal-st-stm32f429zi -IC:/workspace/Blinky3/yotta_modules/cmsis-core-stm32f4/cmsis-core-stm32f4 -IC:/workspace/Blinky3/source -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -DMBED_OPERATORS -DTARGET_STM32F429I_DISCO -DTARGET_STM32F429ZI -DSTM32F429xx -DTARGET_STM32F4 -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -include “C:/workspace/Blinky3/build/stm32f429i-disco-gcc/yotta_config.h” -MMD -MT source/CMakeFiles/blinky3.dir/C_/workspace/Blinky3/source/PreProcessor.cpp.o -MF source/CMakeFiles/blinky3.dir/C_/workspace/Blinky3/source/PreProcessor.cpp.o.d -o source/CMakeFiles/blinky3.dir/C_/workspace/Blinky3/source/PreProcessor.cpp.o -c C:/workspace/Blinky3/source/PreProcessor.cpp
C:/workspace/Blinky3/source/PreProcessor.cpp: In member function ‘void PreProcess::setData(int)’:
C:/workspace/Blinky3/source/PreProcessor.cpp:35:50: error: call of overloaded ‘abs(float)’ is ambiguous
if (toleranceOverride | (abs(data-average) < average * tolerance)) {
^
C:/workspace/Blinky3/source/PreProcessor.cpp:35:50: note: candidates are:
In file included from c:\yotta\gcc\arm-none-eabi\include\stdio.h:29:0,
from C:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32cubef4/mbed-hal-st-stm32cubef4/stm32f4xx_hal_def.h:50,
from C:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32cubef4/mbed-hal-st-stm32cubef4/stm32f4xx_hal_rcc.h:47,
from C:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32f429zi/mbed-hal-st-stm32f429zi/stm32f4xx_hal_conf.h:233,
from C:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32cubef4/mbed-hal-st-stm32cubef4/stm32f4xx_hal.h:48,
from C:/workspace/Blinky3/yotta_modules/cmsis-core-stm32f4/cmsis-core-stm32f4/stm32f4xx.h:213,
from C:/workspace/Blinky3/yotta_modules/cmsis-core-stm32f4/cmsis-core-stm32f4/cmsis.h:35,
from C:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32f4/mbed-hal-st-stm32f4/objects.h:33,
from C:/workspace/Blinky3/yotta_modules/mbed-hal-st-stm32f429zi/mbed-hal-st-stm32f429zi/device.h:72,
from C:/workspace/Blinky3/yotta_modules/mbed-drivers/mbed-drivers/platform.h:22,
from C:/workspace/Blinky3/yotta_modules/mbed-drivers/mbed-drivers/mbed.h:22,
from C:/workspace/Blinky3/source/PreProcessor.h:4,
from C:/workspace/Blinky3/source/PreProcessor.cpp:3:
c:\yotta\gcc\arm-none-eabi\include\stdlib.h:68:5: note: int abs(int)
int _EXFUN(abs,(int));
^
In file included from C:/workspace/Blinky3/yotta_modules/mbed-drivers/mbed-drivers/platform.h:27:0,
from C:/workspace/Blinky3/yotta_modules/mbed-drivers/mbed-drivers/mbed.h:22,
from C:/workspace/Blinky3/source/PreProcessor.h:4,
from C:/workspace/Blinky3/source/PreProcessor.cpp:3:
c:\yotta\gcc\arm-none-eabi\include\c++\4.9.3\cstdlib:174:3: note: long long int std::abs(long long int)
abs(long long __x) { return __builtin_llabs (__x); }
^
c:\yotta\gcc\arm-none-eabi\include\c++\4.9.3\cstdlib:166:3: note: long int std::abs(long int)
abs(long __i) { return __builtin_labs(_i); }
^
[2/3] Building CXX object source/CMakeFiles/blinky3.dir/C
/workspace/Blinky3/source/Blinky3.cpp.o
ninja: build stopped: subcommand failed.
error: command [‘ninja’] failed

Paste in a snippet of your calling code for us to check out also –

Hi,

this is the calling code

<>
void PreProcess::setData(int data)
{
// Usart3.printf(“Tolerance %.2f\n\r”,tolerance);

int i;
if (isarrayFull) {
    if (toleranceOverride) | (abs(data-average) < average * tolerance)) 
    {
        // data is good. place in array and average it
        dataInvalidCount = 0;

        aveArray[arrayPointer++] = data;
        if ( arrayPointer >7)        arrayPointer = 0;

.
.
.

<>

So you’re doing int - float which is a bit weird. Try static_cast<float>(data) - average to make sure it’s a float returned.

If that doesn’t help, does fabsf() work without a warning? Might be something regarding your stdlib. C99 & C++98 handle abs different, see fabs - C++ Reference.

Hi,

thanks for the heads up…

I thought C did all the casting automatically…
I am so ancient, I learned Pascal…:frowning:
in the 80s :frowning:

this original line had a typo…
<>
if (toleranceOverride) | (abs(data-average) < average * tolerance))
<
>

adjusted to
<>
if ((toleranceOverride) | (abs(data-average) < average * tolerance))
<
>
but still did not compile… ( C seems more strict with type casting than I thought)

this complies without error,
<>
if ((toleranceOverride) | (fabs( ((float)data) -average) < average * tolerance))
<
>

Thanks team…
Nick.

janjongboom is able to see something I can’t, but I trust him and if average is indeed a float I expect you’re getting type-promoted from int to float, which none of your included abs() functions can handle to my knowledge (stdlib.h is int only and cstdlib is long and long long only) so I think fabs is the way to go.

I just saw your post … good to see it’s fixed!

Be advised: comparing floating point to zero has bit me in the past. Sometimes math computes stuff to 0.00000001 or similar. If you can substitute in a range or round it back down, you might be better off - unless you are rock solid certain about your math functions.

It was an educated guess :wink:

aha!! I thought maybe my HTML was rendering wrong…