From 6fb04e7fb68117c7d00c8cfbefd251427a85775f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 7 Feb 2022 12:14:45 +1000 Subject: [PATCH] endian: add an f64 bswap test --- test/endian.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test/endian.cpp b/test/endian.cpp index b9fc34ed..a5236431 100644 --- a/test/endian.cpp +++ b/test/endian.cpp @@ -21,19 +21,27 @@ main (void) tap.expect_eq (cruft::readle (bytes), 0xefcdab8967452301, "readle"); } + { + static constexpr u32 A = 0x11223344; + static constexpr u32 B = 0x44332211; + + f32 const a_f = cruft::cast::bit (A); + f32 const b_f = cruft::bswap (a_f); + u32 const b_u = cruft::cast::bit (b_f); + + tap.expect_eq (b_u, B, "f32 bswap"); + } { - // try to byte swap the pattern for 1.0f - // - // it may not be the most robust test, but it'll catch the most - // egregious errors for the time being. - union { - uint32_t u; - float f; - } data { .u = 0x0000803f /* 0x3f800000 == 1.f */ }; + static constexpr u64 A = 0x1122334455667788; + static constexpr u64 B = 0x8877665544332211; - tap.expect_eq (cruft::bswap (data.f), 1.f, "f32 byteswap"); - }; + f64 const a_f = cruft::cast::bit (A); + f64 const b_f = cruft::bswap (a_f); + u64 const b_u = cruft::cast::bit (b_f); + + tap.expect_eq (b_u, B, "u64 bswap"); + } return tap.status (); } \ No newline at end of file