Date: Wed, 27 Aug 2025 06:19:58 +0000
> Arduino Uno and Atmega-based devices are prominent examples where double is a 32 bit float.[1] I believe this is because they do not have a 64-bit FPU. Same with avr-gcc.[2]
> Can we reinterpret_cast double to a float32_t on these platforms?
>
> [1] https://docs.arduino.cc/language-reference/en/variables/data-types/double/
> [2] https://gcc.gnu.org/wiki/avr-gcc
I don't immediately see in those docs whether or not the 32-bit float is IEEE binary32.
For the sake of discussion, let's assume it is.
The docs do say that float and double are identical representations.
Then the proposal would be to allow reinterpret_cast of pointers between float, double, and std::float32_t to work.
Suppose one has code written using type double for a device you mentioned.
Further suppose some third-party provides a library (possibly closed source) that supports std::float32_t and std::float64_t APIs.
To use this library, you want to pass a double* to a function that has a std::float32_t* parameter.
You've made the right choice; you want reinterpret_cast (or C-style cast) to work.
There's merit (if possible) in simplicity for the C++ standard.
Something like, "If T and U are floating-point types having identical representations, then reinterpret_cast<U*>(ptr) works great."
Well, copy and paste better language from the section on std::complex. *smile*
Received on 2025-08-27 06:20:03