mirror of
https://github.com/esphome/esphome.git
synced 2026-09-19 02:58:38 +00:00
Use union instead of memcpy in float_to_raw — xtensa-gcc doesn't optimize memcpy in all contexts
This commit is contained in:
@@ -27,9 +27,12 @@ constexpr uint8_t WIRE_TYPE_MASK = 0b111; // Mask to extract wire type
|
||||
// Reinterpret float bits as uint32_t without floating-point comparison.
|
||||
// Used by both encode_float() and calc_float() to ensure identical zero checks.
|
||||
inline uint32_t float_to_raw(float value) {
|
||||
uint32_t raw;
|
||||
memcpy(&raw, &value, sizeof(raw));
|
||||
return raw;
|
||||
union {
|
||||
float f;
|
||||
uint32_t u;
|
||||
} v;
|
||||
v.f = value;
|
||||
return v.u;
|
||||
}
|
||||
|
||||
// Helper functions for ZigZag encoding/decoding
|
||||
|
||||
Reference in New Issue
Block a user