bit_cast
namespace opentl {
template <typename To, typename From>
constexpr To bit_cast(const From& from) noexcept;
}
Reinterprets the bits of one type as another type.
Template Parameters
| Name | Description |
|---|---|
To |
The type to reinterpret the bits as. |
From |
The type to reinterpret the bits from. |
Parameters
| Name | Description |
|---|---|
from |
The value to reinterpret. |
Return Value
The bits of from, reinterpreted as To.
Example
#include <utility.hpp>
int main() {
int i = 0x3F800000; // 1.0f in IEEE-754
float f = opentl::bit_cast<float>(i); // 1.0f
static_assert(opentl::bit_cast<int>(1.0f) == 0x3F800000);
}