1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Avoid float-double-conversion (#7559)

Converting floats to doubles is very expensive on esp8266, so prefer
calculations or comparisons as float. This saves 10% (20 bytes) of the
String::parseFloat() code size and probably quite a bit of runtime
overhead.
This commit is contained in:
Dirk Mueller 2020-08-28 23:09:44 +02:00 committed by GitHub
parent 59873908c4
commit 953dfd945f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -173,7 +173,7 @@ float Stream::parseFloat(char skipChar) {
boolean isFraction = false;
long value = 0;
int c;
float fraction = 1.0;
float fraction = 1.0f;
c = peekNextDigit();
// ignore non numeric leading characters
@ -190,7 +190,7 @@ float Stream::parseFloat(char skipChar) {
else if(c >= '0' && c <= '9') { // is c a digit?
value = value * 10 + c - '0';
if(isFraction)
fraction *= 0.1;
fraction *= 0.1f;
}
read(); // consume the character we got with peek
c = timedPeek();

View File

@ -369,10 +369,10 @@ WiFiPhyMode_t ESP8266WiFiGenericClass::getPhyMode() {
*/
void ESP8266WiFiGenericClass::setOutputPower(float dBm) {
if(dBm > 20.5) {
dBm = 20.5;
} else if(dBm < 0) {
dBm = 0;
if(dBm > 20.5f) {
dBm = 20.5f;
} else if(dBm < 0.0f) {
dBm = 0.0f;
}
uint8_t val = (dBm*4.0f);