Skip to content

Commit 03885a6

Browse files
authored
Fix undefined std::round compilation error (#1989)
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.
1 parent 1f79fee commit 03885a6

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/IRac.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#include <string>
1414
#endif
1515
#include <cmath>
16+
#if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_MATH_TR1)
17+
using std::roundf;
18+
#else
19+
using ::roundf;
20+
#endif
1621
#include "IRsend.h"
1722
#include "IRremoteESP8266.h"
1823
#include "IRtext.h"
@@ -489,9 +494,9 @@ void IRac::argo(IRArgoAC *ac,
489494
ac->begin();
490495
ac->setPower(on);
491496
ac->setMode(ac->convertMode(mode));
492-
ac->setTemp(static_cast<uint8_t>(std::round(degrees)));
497+
ac->setTemp(static_cast<uint8_t>(roundf(degrees)));
493498
if (sensorTemp != kNoTempValue) {
494-
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
499+
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
495500
}
496501
ac->setiFeel(iFeel);
497502
ac->setFan(ac->convertFan(fan));
@@ -537,7 +542,7 @@ void IRac::argoWrem3_ACCommand(IRArgoAC_WREM3 *ac, const bool on,
537542
ac->setMode(ac->convertMode(mode));
538543
ac->setTemp(degrees);
539544
if (sensorTemp != kNoTempValue) {
540-
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
545+
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
541546
}
542547
ac->setiFeel(iFeel);
543548
ac->setFan(ac->convertFan(fan));
@@ -563,7 +568,7 @@ void IRac::argoWrem3_ACCommand(IRArgoAC_WREM3 *ac, const bool on,
563568
void IRac::argoWrem3_iFeelReport(IRArgoAC_WREM3 *ac, const float sensorTemp) {
564569
ac->begin();
565570
ac->setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT);
566-
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
571+
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
567572
ac->send();
568573
}
569574

@@ -738,7 +743,7 @@ void IRac::coolix(IRCoolixAC *ac,
738743
// No Econo setting available.
739744
// No Quiet setting available.
740745
if (sensorTemp != kNoTempValue) {
741-
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
746+
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
742747
} else {
743748
ac->clearSensorTemp();
744749
}
@@ -1128,7 +1133,7 @@ void IRac::ecoclim(IREcoclimAc *ac,
11281133
ac->setTemp(degrees);
11291134
ac->setFan(ac->convertFan(fan));
11301135
if (sensorTemp != kNoTempValue) {
1131-
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
1136+
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
11321137
} else {
11331138
ac->setSensorTemp(degrees); //< Set to the desired temp
11341139
// until we can disable.
@@ -1174,7 +1179,7 @@ void IRac::electra(IRElectraAc *ac,
11741179
ac->setMode(ac->convertMode(mode));
11751180
ac->setTemp(degrees);
11761181
if (sensorTemp != kNoTempValue) {
1177-
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
1182+
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
11781183
}
11791184
ac->setFan(ac->convertFan(fan));
11801185
ac->setSwingV(swingv != stdAc::swingv_t::kOff);
@@ -2288,7 +2293,7 @@ void IRac::sanyo(IRSanyoAc *ac,
22882293
ac->setMode(ac->convertMode(mode));
22892294
ac->setTemp(degrees);
22902295
if (sensorTemp != kNoTempValue) {
2291-
ac->setSensorTemp(static_cast<uint8_t>(std::round(sensorTemp)));
2296+
ac->setSensorTemp(static_cast<uint8_t>(roundf(sensorTemp)));
22922297
} else {
22932298
ac->setSensorTemp(degrees); // Set the sensor temp to the desired
22942299
// (normal) temp.

0 commit comments

Comments
 (0)