mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 12:35:25 +00:00
[multiple] Avoid float-to-double promotion in math calls (#16812)
This commit is contained in:
@@ -216,7 +216,7 @@ uint8_t DaikinArcClimate::temperature_() {
|
||||
return 0xc0;
|
||||
default:
|
||||
float new_temp = clamp<float>(this->target_temperature, DAIKIN_TEMP_MIN, DAIKIN_TEMP_MAX);
|
||||
uint8_t temperature = (uint8_t) floor(new_temp);
|
||||
uint8_t temperature = (uint8_t) std::floor(new_temp);
|
||||
return temperature << 1 | (new_temp - temperature > 0 ? 0x01 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "display.h"
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
#include <numbers>
|
||||
#include "display_color_utils.h"
|
||||
@@ -238,7 +239,7 @@ void Display::filled_gauge(int center_x, int center_y, int radius1, int radius2,
|
||||
int lhline_width = -(dxmax - dxmin) + 1;
|
||||
if (progress >= 50) {
|
||||
if (float(dymax) < float(-dxmax) * tan_a) {
|
||||
upd_dxmax = ceil(float(dymax) / tan_a);
|
||||
upd_dxmax = std::ceil(float(dymax) / tan_a);
|
||||
} else {
|
||||
upd_dxmax = -dxmax;
|
||||
}
|
||||
@@ -253,7 +254,7 @@ void Display::filled_gauge(int center_x, int center_y, int radius1, int radius2,
|
||||
}
|
||||
} else {
|
||||
if (float(dymin) > float(-dxmin) * tan_a) {
|
||||
upd_dxmin = ceil(float(dymin) / tan_a);
|
||||
upd_dxmin = std::ceil(float(dymin) / tan_a);
|
||||
} else {
|
||||
upd_dxmin = -dxmin;
|
||||
}
|
||||
@@ -268,12 +269,12 @@ void Display::filled_gauge(int center_x, int center_y, int radius1, int radius2,
|
||||
int hline_width = 2 * (-dxmax) + 1;
|
||||
if (progress >= 50) {
|
||||
if (dymax < float(-dxmax) * tan_a) {
|
||||
upd_dxmax = ceil(float(dymax) / tan_a);
|
||||
upd_dxmax = std::ceil(float(dymax) / tan_a);
|
||||
hline_width = -dxmax + upd_dxmax + 1;
|
||||
}
|
||||
} else {
|
||||
if (dymax < float(-dxmax) * tan_a) {
|
||||
upd_dxmax = ceil(float(dymax) / tan_a);
|
||||
upd_dxmax = std::ceil(float(dymax) / tan_a);
|
||||
hline_width = -dxmax - upd_dxmax + 1;
|
||||
} else {
|
||||
hline_width = 0;
|
||||
@@ -452,8 +453,8 @@ void HOT Display::get_regular_polygon_vertex(int vertex_id, int *vertex_x, int *
|
||||
rotation_radians -= (variation == VARIATION_FLAT_TOP) ? std::numbers::pi / edges : 0.0;
|
||||
|
||||
float vertex_angle = ((float) vertex_id) / edges * 2 * std::numbers::pi + rotation_radians;
|
||||
*vertex_x = (int) round(cos(vertex_angle) * radius) + center_x;
|
||||
*vertex_y = (int) round(sin(vertex_angle) * radius) + center_y;
|
||||
*vertex_x = (int) std::round(std::cos(vertex_angle) * radius) + center_x;
|
||||
*vertex_y = (int) std::round(std::sin(vertex_angle) * radius) + center_y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
|
||||
void setup(); // NOLINT(readability-redundant-declaration)
|
||||
|
||||
// Weak stub for initArduino - overridden when the Arduino component is present
|
||||
// Weak stub for initArduino - overridden when the Arduino component is present.
|
||||
// Name must match the Arduino framework's entry point, so the naming check is suppressed.
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
extern "C" __attribute__((weak)) void initArduino() {}
|
||||
|
||||
namespace esphome {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "nau7802.h"
|
||||
#include <cmath>
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
@@ -76,7 +77,7 @@ void NAU7802Sensor::setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t gcal = (uint32_t) (round(this->gain_calibration_ * (1 << GCAL1_FRACTIONAL)));
|
||||
uint32_t gcal = (uint32_t) (std::round(this->gain_calibration_ * (1 << GCAL1_FRACTIONAL)));
|
||||
this->write_value_(OCAL1_B2_REG, 3, this->offset_calibration_);
|
||||
this->write_value_(GCAL1_B3_REG, 4, gcal);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
|
||||
namespace esphome::sgp4x {
|
||||
|
||||
@@ -199,7 +200,7 @@ void SGP4xComponent::measure_raw_() {
|
||||
response_words = 2;
|
||||
}
|
||||
}
|
||||
uint16_t rhticks = (uint16_t) llround((humidity * 65535) / 100);
|
||||
uint16_t rhticks = (uint16_t) std::llround((humidity * 65535) / 100);
|
||||
uint16_t tempticks = (uint16_t) (((temperature + 45) * 65535) / 175);
|
||||
// first parameter are the relative humidity ticks
|
||||
data[0] = rhticks;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "thermopro_ble.h"
|
||||
#include <cmath>
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
@@ -136,7 +137,7 @@ static inline uint32_t read_uint32(const uint8_t *data, std::size_t offset) {
|
||||
// A*tanh(B*x+C)+D
|
||||
// Where A,B,C,D are the variables to optimize for. This yielded the below function
|
||||
static float tp96_battery(uint16_t voltage) {
|
||||
float level = 52.317286f * tanh(static_cast<float>(voltage) / 273.624277936f - 8.76485439394f) + 51.06925f;
|
||||
float level = 52.317286f * std::tanh(static_cast<float>(voltage) / 273.624277936f - 8.76485439394f) + 51.06925f;
|
||||
return std::max(0.0f, std::min(level, 100.0f));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
#include "tuya_number.h"
|
||||
|
||||
@@ -63,7 +65,7 @@ void TuyaNumber::setup() {
|
||||
void TuyaNumber::control(float value) {
|
||||
ESP_LOGV(TAG, "Setting number %u: %f", this->number_id_, value);
|
||||
if (this->type_ == TuyaDatapointType::INTEGER) {
|
||||
int integer_value = lround(value * multiply_by_);
|
||||
int integer_value = std::lround(value * multiply_by_);
|
||||
this->parent_->set_integer_datapoint_value(this->number_id_, integer_value);
|
||||
} else if (this->type_ == TuyaDatapointType::ENUM) {
|
||||
this->parent_->set_enum_datapoint_value(this->number_id_, value);
|
||||
|
||||
Reference in New Issue
Block a user