From 1cb8bf6308a5ef255a93d96ea4003273ab6dee4f Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Mon, 29 May 2023 18:41:07 -0600 Subject: [PATCH] AP_Common: Remove type punning utils to AP_Math Signed-off-by: Ryan Friedman --- libraries/AP_Common/AP_Common.cpp | 36 ------------------------------- libraries/AP_Common/AP_Common.h | 15 ------------- 2 files changed, 51 deletions(-) diff --git a/libraries/AP_Common/AP_Common.cpp b/libraries/AP_Common/AP_Common.cpp index 07862161b7..19c403c353 100644 --- a/libraries/AP_Common/AP_Common.cpp +++ b/libraries/AP_Common/AP_Common.cpp @@ -101,39 +101,3 @@ int16_t char_to_hex(char a) else return a - '0'; } - -int32_t to_int32(const float value) -{ - int32_t out; - static_assert(sizeof(value) == sizeof(out)); - - // Use memcpy because it's the most portable. - // It might not be the fastest way on all hardware. - // At least it's defined behavior in both c and c++. - memcpy(&out, &value, sizeof(out)); - return out; -} - -float to_float(const uint32_t value) -{ - float out; - static_assert(sizeof(value) == sizeof(out)); - - // Use memcpy because it's the most portable. - // It might not be the fastest way on all hardware. - // At least it's defined behavior in both c and c++. - memcpy(&out, &value, sizeof(out)); - return out; -} - -double to_double(const uint64_t value) -{ - double out; - static_assert(sizeof(value) == sizeof(out)); - - // Use memcpy because it's the most portable. - // It might not be the fastest way on all hardware. - // At least it's defined behavior in both c and c++. - memcpy(&out, &value, sizeof(out)); - return out; -} diff --git a/libraries/AP_Common/AP_Common.h b/libraries/AP_Common/AP_Common.h index c460c7fef3..5949ca14cf 100644 --- a/libraries/AP_Common/AP_Common.h +++ b/libraries/AP_Common/AP_Common.h @@ -179,18 +179,3 @@ template void BIT_CLEAR (T& value, uint8_t bitnumber) noexcept { ((value) &= ~((T)(1U) << (bitnumber))); } - -/* - Convert from float to int32_t without breaking Wstrict-aliasing due to type punning -*/ -int32_t to_int32(const float value) WARN_IF_UNUSED; - -/* - Convert from uint32_t to float without breaking Wstrict-aliasing due to type punning -*/ -float to_float(const uint32_t value) WARN_IF_UNUSED; - -/* - Convert from uint64_t to double without breaking Wstrict-aliasing due to type punning -*/ -double to_double(const uint64_t value) WARN_IF_UNUSED;