crankyoldgit / IRremoteESP8266

Infrared remote library for ESP8266/ESP32: send and receive infrared signals with multiple protocols. Based on: https://github.com/shirriff/Arduino-IRremote/
GNU Lesser General Public License v2.1
3k stars 833 forks source link

Fix undefined `std::round` compilation error #1989

Closed devnoname120 closed 1 year ago

devnoname120 commented 1 year ago

In some implementations round is at the global scope as ::round and some other implementations make it available as std::round.

The changes use the float roundf(float) flavor to make sure that we don't use double round(double) if this function isn't overloaded with the float type.

Here is the error that it fixes when compiling https://github.com/sharandac/My-TTGO-Watch/:

Building in release mode
Compiling .pio/build/t-watch2020-v3/lib878/IRremoteESP8266/IRac.cpp.o
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp: In member function 'void IRac::argo(IRArgoAC*, bool, stdAc::opmode_t, float, float, stdAc::fanspeed_t, stdAc::swingv_t, bool, bool, int16_t)':
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:492:36: error: 'round' is not a member of 'std'
   ac->setTemp(static_cast<uint8_t>(std::round(degrees)));
                                    ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:492:36: note: suggested alternative:
In file included from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:34:0,
                 from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.h:7,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:7:
/Users/devnoname120/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/math.h:278:15: note:   'round'
 extern double round _PARAMS((double));
               ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:494:44: error: 'round' is not a member of 'std'
     ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
                                            ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:494:44: note: suggested alternative:
In file included from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:34:0,
                 from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.h:7,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:7:
/Users/devnoname120/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/math.h:278:15: note:   'round'
 extern double round _PARAMS((double));
               ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp: In member function 'void IRac::argoWrem3_ACCommand(IRArgoAC_WREM3*, bool, stdAc::opmode_t, float, float, stdAc::fanspeed_t, stdAc::swingv_t, bool, bool, bool, bool, bool, bool)':
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:540:44: error: 'round' is not a member of 'std'
     ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
                                            ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:540:44: note: suggested alternative:
In file included from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:34:0,
                 from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.h:7,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:7:
/Users/devnoname120/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/math.h:278:15: note:   'round'
 extern double round _PARAMS((double));
               ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp: In member function 'void IRac::argoWrem3_iFeelReport(IRArgoAC_WREM3*, float)':
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:566:42: error: 'round' is not a member of 'std'
   ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
                                          ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:566:42: note: suggested alternative:
In file included from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:34:0,
                 from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.h:7,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:7:
/Users/devnoname120/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/math.h:278:15: note:   'round'
 extern double round _PARAMS((double));
               ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp: In member function 'void IRac::coolix(IRCoolixAC*, bool, stdAc::opmode_t, float, float, stdAc::fanspeed_t, stdAc::swingv_t, stdAc::swingh_t, bool, bool, bool, bool, int16_t)':
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:741:44: error: 'round' is not a member of 'std'
     ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
                                            ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:741:44: note: suggested alternative:
In file included from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:34:0,
                 from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.h:7,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:7:
/Users/devnoname120/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/math.h:278:15: note:   'round'
 extern double round _PARAMS((double));
               ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp: In member function 'void IRac::ecoclim(IREcoclimAc*, bool, stdAc::opmode_t, float, float, stdAc::fanspeed_t, int16_t, int16_t)':
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:1131:44: error: 'round' is not a member of 'std'
     ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
                                            ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:1131:44: note: suggested alternative:
In file included from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:34:0,
                 from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.h:7,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:7:
/Users/devnoname120/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/math.h:278:15: note:   'round'
 extern double round _PARAMS((double));
               ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp: In member function 'void IRac::electra(IRElectraAc*, bool, stdAc::opmode_t, float, float, stdAc::fanspeed_t, stdAc::swingv_t, stdAc::swingh_t, bool, bool, bool, bool)':
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:1177:44: error: 'round' is not a member of 'std'
     ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
                                            ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:1177:44: note: suggested alternative:
In file included from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:34:0,
                 from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.h:7,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:7:
/Users/devnoname120/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/math.h:278:15: note:   'round'
 extern double round _PARAMS((double));
               ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp: In member function 'void IRac::sanyo(IRSanyoAc*, bool, stdAc::opmode_t, float, float, stdAc::fanspeed_t, stdAc::swingv_t, bool, bool, int16_t)':
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:2291:44: error: 'round' is not a member of 'std'
     ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
                                            ^
.pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:2291:44: note: suggested alternative:
In file included from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:34:0,
                 from /Users/devnoname120/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:35,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.h:7,
                 from .pio/libdeps/t-watch2020-v3/IRremoteESP8266/src/IRac.cpp:7:
/Users/devnoname120/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib/math.h:278:15: note:   'round'
 extern double round _PARAMS((double));
               ^
*** [.pio/build/t-watch2020-v3/lib878/IRremoteESP8266/IRac.cpp.o] Error 1
devnoname120 commented 1 year ago

Thanks!