endian: add an f64 bswap test

This commit is contained in:
Danny Robson 2022-02-07 12:14:45 +10:00
parent c963fce304
commit 6fb04e7fb6

View File

@ -21,19 +21,27 @@ main (void)
tap.expect_eq (cruft::readle<std::uint64_t> (bytes), 0xefcdab8967452301, "readle<u64>");
}
{
static constexpr u32 A = 0x11223344;
static constexpr u32 B = 0x44332211;
f32 const a_f = cruft::cast::bit<f32> (A);
f32 const b_f = cruft::bswap (a_f);
u32 const b_u = cruft::cast::bit<u32> (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<f64> (A);
f64 const b_f = cruft::bswap (a_f);
u64 const b_u = cruft::cast::bit<u64> (b_f);
tap.expect_eq (b_u, B, "u64 bswap");
}
return tap.status ();
}