| 1 | // Test for boost/core/bit.hpp (bit_cast) |
|---|---|
| 2 | // |
| 3 | // Copyright 2020 Peter Dimov |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // https://www.boost.org/LICENSE_1_0.txt |
| 6 | |
| 7 | #include <boost/core/bit.hpp> |
| 8 | #include <boost/core/lightweight_test.hpp> |
| 9 | #include <boost/cstdint.hpp> |
| 10 | #include <cstring> |
| 11 | |
| 12 | int main() |
| 13 | { |
| 14 | { |
| 15 | float x = 0.89f; |
| 16 | boost::uint32_t y = boost::core::bit_cast<boost::uint32_t>( from: x ); |
| 17 | |
| 18 | BOOST_TEST( std::memcmp( &x, &y, sizeof(x) ) == 0 ); |
| 19 | } |
| 20 | |
| 21 | { |
| 22 | double x = 0.89; |
| 23 | boost::uint64_t y = boost::core::bit_cast<boost::uint64_t>( from: x ); |
| 24 | |
| 25 | BOOST_TEST( std::memcmp( &x, &y, sizeof(x) ) == 0 ); |
| 26 | } |
| 27 | |
| 28 | return boost::report_errors(); |
| 29 | } |
| 30 |
