Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined std::round compilation error #1989

Conversation

devnoname120
Copy link
Contributor

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

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.
@crankyoldgit crankyoldgit self-requested a review May 12, 2023 15:57
@crankyoldgit crankyoldgit self-assigned this May 12, 2023
@crankyoldgit crankyoldgit merged commit 03885a6 into crankyoldgit:master May 12, 2023
@devnoname120
Copy link
Contributor Author

Thanks!

@devnoname120 devnoname120 deleted the devnoname120/fix-undefined-std_round branch May 12, 2023 16:14
crankyoldgit added a commit that referenced this pull request Jul 27, 2023
_v2.8.6 (20230727)_

**[Bug Fixes]**
- Ensure `IRCoolixAC::toCommon()` returns `kNoTempValue` when no sensor temp is detected. (#2015 #2012)
- Fix compilation dependency of LG on Samsung send protocol (#2011 #2010)
- Fix missing parameter in call to `IRac::gree()` (#2008 #2007)

**[Features]**
- IRac: Ensure the `sleep` parameter is used for the `FUJITSU_AC` protocol. (#1992 #1991)

**[Misc]**
- Allow the BlynkIRRemote.ino code to compile again. (#2016)
- do not list WHIRLPOOL_AC unconditionally as supported protocol (#2003)
- IRUtils:typeToString() — simplify (#2002)
- Fix brand Green -> Gree (#1994)
- Fix undefined `std::round` compilation error (#1989)
@crankyoldgit crankyoldgit mentioned this pull request Jul 27, 2023
crankyoldgit added a commit that referenced this pull request Jul 28, 2023
## _v2.8.6 (20230727)_

**[Bug Fixes]**
- Ensure `IRCoolixAC::toCommon()` returns `kNoTempValue` when no sensor temp is detected. (#2015 #2012)
- Fix compilation dependency of LG on Samsung send protocol (#2011 #2010)
- Fix missing parameter in call to `IRac::gree()` (#2008 #2007)

**[Features]**
- IRac: Ensure the `sleep` parameter is used for the `FUJITSU_AC` protocol. (#1992 #1991)

**[Misc]**
- Allow the BlynkIRRemote.ino code to compile again. (#2016)
- do not list WHIRLPOOL_AC unconditionally as supported protocol (#2003)
- IRUtils:typeToString() — simplify (#2002)
- Fix brand Green -> Gree (#1994)
- Fix undefined `std::round` compilation error (#1989)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants