Skip to content

Commit

Permalink
Fix undefined std::round compilation error (#1989)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devnoname120 authored May 12, 2023
1 parent 1f79fee commit 03885a6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include <string>
#endif
#include <cmath>
#if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_MATH_TR1)
using std::roundf;
#else
using ::roundf;
#endif
#include "IRsend.h"
#include "IRremoteESP8266.h"
#include "IRtext.h"
Expand Down Expand Up @@ -489,9 +494,9 @@ void IRac::argo(IRArgoAC *ac,
ac->begin();
ac->setPower(on);
ac->setMode(ac->convertMode(mode));
ac->setTemp(static_cast<uint8_t>(std::round(degrees)));
ac->setTemp(static_cast<uint8_t>(roundf(degrees)));
if (sensorTemp != kNoTempValue) {
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
}
ac->setiFeel(iFeel);
ac->setFan(ac->convertFan(fan));
Expand Down Expand Up @@ -537,7 +542,7 @@ void IRac::argoWrem3_ACCommand(IRArgoAC_WREM3 *ac, const bool on,
ac->setMode(ac->convertMode(mode));
ac->setTemp(degrees);
if (sensorTemp != kNoTempValue) {
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
}
ac->setiFeel(iFeel);
ac->setFan(ac->convertFan(fan));
Expand All @@ -563,7 +568,7 @@ void IRac::argoWrem3_ACCommand(IRArgoAC_WREM3 *ac, const bool on,
void IRac::argoWrem3_iFeelReport(IRArgoAC_WREM3 *ac, const float sensorTemp) {
ac->begin();
ac->setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT);
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
ac->send();
}

Expand Down Expand Up @@ -738,7 +743,7 @@ void IRac::coolix(IRCoolixAC *ac,
// No Econo setting available.
// No Quiet setting available.
if (sensorTemp != kNoTempValue) {
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
} else {
ac->clearSensorTemp();
}
Expand Down Expand Up @@ -1128,7 +1133,7 @@ void IRac::ecoclim(IREcoclimAc *ac,
ac->setTemp(degrees);
ac->setFan(ac->convertFan(fan));
if (sensorTemp != kNoTempValue) {
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
} else {
ac->setSensorTemp(degrees); //< Set to the desired temp
// until we can disable.
Expand Down Expand Up @@ -1174,7 +1179,7 @@ void IRac::electra(IRElectraAc *ac,
ac->setMode(ac->convertMode(mode));
ac->setTemp(degrees);
if (sensorTemp != kNoTempValue) {
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
}
ac->setFan(ac->convertFan(fan));
ac->setSwingV(swingv != stdAc::swingv_t::kOff);
Expand Down Expand Up @@ -2288,7 +2293,7 @@ void IRac::sanyo(IRSanyoAc *ac,
ac->setMode(ac->convertMode(mode));
ac->setTemp(degrees);
if (sensorTemp != kNoTempValue) {
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
} else {
ac->setSensorTemp(degrees); // Set the sensor temp to the desired
// (normal) temp.
Expand Down

0 comments on commit 03885a6

Please # to comment.