cast_test.cpp 829 B

123456789101112131415161718192021222324
  1. /*
  2. * Copyright 2010-2024 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
  4. */
  5. #include "test.h"
  6. #include <bx/bx.h>
  7. #include <string.h>
  8. TEST_CASE("Bit cast", "[cast]")
  9. {
  10. STATIC_REQUIRE(0x4172f58bc0000000ull == bx::bitCast<uint64_t>(19880124.0) );
  11. STATIC_REQUIRE(0x3fe9000000000000ull == bx::bitCast<uint64_t>(0.781250) );
  12. STATIC_REQUIRE(19880124.0 == bx::bitCast<double>(0x4172f58bc0000000ull) );
  13. STATIC_REQUIRE(0.781250 == bx::bitCast<double>(0x3fe9000000000000ull) );
  14. }
  15. TEST_CASE("Narrow cast", "[cast]")
  16. {
  17. REQUIRE(127 == bx::narrowCast<int8_t>(int32_t(127) ) );
  18. REQUIRE_ASSERTS(bx::narrowCast<int8_t>(int32_t(128) ) );
  19. REQUIRE_ASSERTS(bx::narrowCast<int8_t>(uint32_t(128) ) );
  20. REQUIRE(128 == bx::narrowCast<uint8_t>(int32_t(128) ) );
  21. }