Skip to content

Commit 1c58e68

Browse files
committed
Fix float literals and implicit conversions
1 parent 2295fe4 commit 1c58e68

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

DHT.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ float DHT::readTemperature(bool S, bool force) {
9090
case DHT11:
9191
f = data[2];
9292
if (data[3] & 0x80) {
93-
f = -1 - f;
93+
f = -1.F - f;
9494
}
95-
f += (data[3] & 0x0f) * 0.1;
95+
f += (data[3] & 0x0f) * 0.1F;
9696
if (S) {
9797
f = convertCtoF(f);
9898
}
9999
break;
100100
case DHT12:
101101
f = data[2];
102-
f += (data[3] & 0x0f) * 0.1;
102+
f += (data[3] & 0x0f) * 0.1F;
103103
if (data[2] & 0x80) {
104-
f *= -1;
104+
f *= -1.F;
105105
}
106106
if (S) {
107107
f = convertCtoF(f);
@@ -110,9 +110,9 @@ float DHT::readTemperature(bool S, bool force) {
110110
case DHT22:
111111
case DHT21:
112112
f = ((word)(data[2] & 0x7F)) << 8 | data[3];
113-
f *= 0.1;
113+
f *= 0.1F;
114114
if (data[2] & 0x80) {
115-
f *= -1;
115+
f *= -1.F;
116116
}
117117
if (S) {
118118
f = convertCtoF(f);
@@ -129,15 +129,15 @@ float DHT::readTemperature(bool S, bool force) {
129129
* value in Celcius
130130
* @return float value in Fahrenheit
131131
*/
132-
float DHT::convertCtoF(float c) { return c * 1.8 + 32; }
132+
float DHT::convertCtoF(float c) { return c * 1.8F + 32.F; }
133133

134134
/*!
135135
* @brief Converts Fahrenheit to Celcius
136136
* @param f
137137
* value in Fahrenheit
138138
* @return float value in Celcius
139139
*/
140-
float DHT::convertFtoC(float f) { return (f - 32) * 0.55555; }
140+
float DHT::convertFtoC(float f) { return (f - 32.F) * 0.55555F; }
141141

142142
/*!
143143
* @brief Read Humidity
@@ -151,12 +151,12 @@ float DHT::readHumidity(bool force) {
151151
switch (_type) {
152152
case DHT11:
153153
case DHT12:
154-
f = data[0] + data[1] * 0.1;
154+
f = data[0] + data[1] * 0.1F;
155155
break;
156156
case DHT22:
157157
case DHT21:
158158
f = ((word)data[0]) << 8 | data[1];
159-
f *= 0.1;
159+
f *= 0.1F;
160160
break;
161161
}
162162
}
@@ -196,26 +196,26 @@ float DHT::computeHeatIndex(float temperature, float percentHumidity,
196196
if (!isFahrenheit)
197197
temperature = convertCtoF(temperature);
198198

199-
hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) +
200-
(percentHumidity * 0.094));
201-
202-
if (hi > 79) {
203-
hi = -42.379 + 2.04901523 * temperature + 10.14333127 * percentHumidity +
204-
-0.22475541 * temperature * percentHumidity +
205-
-0.00683783 * pow(temperature, 2) +
206-
-0.05481717 * pow(percentHumidity, 2) +
207-
0.00122874 * pow(temperature, 2) * percentHumidity +
208-
0.00085282 * temperature * pow(percentHumidity, 2) +
209-
-0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);
210-
211-
if ((percentHumidity < 13) && (temperature >= 80.0) &&
212-
(temperature <= 112.0))
213-
hi -= ((13.0 - percentHumidity) * 0.25) *
214-
sqrt((17.0 - abs(temperature - 95.0)) * 0.05882);
215-
216-
else if ((percentHumidity > 85.0) && (temperature >= 80.0) &&
217-
(temperature <= 87.0))
218-
hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2);
199+
hi = 0.5F * (temperature + 61.0F + ((temperature - 68.0F) * 1.2F) +
200+
(percentHumidity * 0.094F));
201+
202+
if (hi > 79.F) {
203+
hi = -42.379F + 2.04901523F * temperature + 10.14333127F * percentHumidity +
204+
-0.22475541F * temperature * percentHumidity +
205+
-0.00683783F * pow(temperature, 2.F) +
206+
-0.05481717F * pow(percentHumidity, 2.F) +
207+
0.00122874F * pow(temperature, 2.F) * percentHumidity +
208+
0.00085282F * temperature * pow(percentHumidity, 2.F) +
209+
-0.00000199F * pow(temperature, 2.F) * pow(percentHumidity, 2.F);
210+
211+
if ((percentHumidity < 13.F) && (temperature >= 80.0F) &&
212+
(temperature <= 112.0F))
213+
hi -= ((13.0F - percentHumidity) * 0.25F) *
214+
sqrt((17.0F - abs(temperature - 95.0F)) * 0.05882F);
215+
216+
else if ((percentHumidity > 85.0F) && (temperature >= 80.0F) &&
217+
(temperature <= 87.0F))
218+
hi += ((percentHumidity - 85.0F) * 0.1F) * ((87.0F - temperature) * 0.2F);
219219
}
220220

221221
return isFahrenheit ? hi : convertFtoC(hi);

0 commit comments

Comments
 (0)