Serenity Operating System
at master 23 lines 548 B view raw
1/* 2 * Copyright (c) 2021, the SerenityOS developers. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibTest/TestCase.h> 8 9#include <AK/BitCast.h> 10 11template<typename A, typename B> 12void check_cast_both_ways(A const& a, B const& b) 13{ 14 EXPECT_EQ((bit_cast<A, B>(b)), a); 15 EXPECT_EQ((bit_cast<B, A>(a)), b); 16} 17 18TEST_CASE(double_int_conversion) 19{ 20 check_cast_both_ways(static_cast<u64>(0), 0.0); 21 check_cast_both_ways(static_cast<u64>(1) << 63, -0.0); 22 check_cast_both_ways(static_cast<u64>(0x4172f58bc0000000), 19880124.0); 23}