| 1 |
/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */ |
| 2 |
|
| 3 |
#ifndef MPT_ENDIAN_TESTS_ENDIAN_FLOATINGPOINT_HPP |
| 4 |
#define MPT_ENDIAN_TESTS_ENDIAN_FLOATINGPOINT_HPP |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "mpt/base/detect_compiler.hpp" |
| 9 |
#include "mpt/base/memory.hpp" |
| 10 |
#include "mpt/base/namespace.hpp" |
| 11 |
#include "mpt/endian/floatingpoint.hpp" |
| 12 |
#include "mpt/test/test.hpp" |
| 13 |
#include "mpt/test/test_macros.hpp" |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
namespace mpt { |
| 18 |
inline namespace MPT_INLINE_NS { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace tests { |
| 23 |
namespace endian { |
| 24 |
namespace floatingpoint { |
| 25 |
|
| 26 |
#if MPT_COMPILER_CLANG |
| 27 |
#pragma clang diagnostic push |
| 28 |
#pragma clang diagnostic ignored "-Wglobal-constructors" |
| 29 |
#endif |
| 30 |
MPT_TEST_GROUP_INLINE("mpt/endian/floatingpoint") |
| 31 |
#if MPT_COMPILER_CLANG |
| 32 |
#pragma clang diagnostic pop |
| 33 |
#endif |
| 34 |
{ |
| 35 |
MPT_TEST_EXPECT_EQUAL(mpt::EncodeIEEE754binary32(1.0f), 0x3f800000u); |
| 36 |
MPT_TEST_EXPECT_EQUAL(mpt::EncodeIEEE754binary32(-1.0f), 0xbf800000u); |
| 37 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary32(0x00000000u), 0.0f); |
| 38 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary32(0x41840000u), 16.5f); |
| 39 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary32(0x3faa0000u), 1.328125f); |
| 40 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary32(0xbfaa0000u), -1.328125f); |
| 41 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary32(0x3f800000u), 1.0f); |
| 42 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary32(0x00000000u), 0.0f); |
| 43 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary32(0xbf800000u), -1.0f); |
| 44 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary32(0x3f800000u), 1.0f); |
| 45 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary32LE(1.0f).GetInt32(), 0x3f800000u); |
| 46 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary32BE(1.0f).GetInt32(), 0x3f800000u); |
| 47 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary32LE(mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x80), mpt::as_byte(0x3f)), 1.0f); |
| 48 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary32BE(mpt::as_byte(0x3f), mpt::as_byte(0x80), mpt::as_byte(0x00), mpt::as_byte(0x00)), 1.0f); |
| 49 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary32LE(1.0f), IEEE754binary32LE(mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x80), mpt::as_byte(0x3f))); |
| 50 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary32BE(1.0f), IEEE754binary32BE(mpt::as_byte(0x3f), mpt::as_byte(0x80), mpt::as_byte(0x00), mpt::as_byte(0x00))); |
| 51 |
|
| 52 |
MPT_TEST_EXPECT_EQUAL(mpt::EncodeIEEE754binary64(1.0), 0x3ff0000000000000ull); |
| 53 |
MPT_TEST_EXPECT_EQUAL(mpt::EncodeIEEE754binary64(-1.0), 0xbff0000000000000ull); |
| 54 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary64(0x0000000000000000ull), 0.0); |
| 55 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary64(0x4030800000000000ull), 16.5); |
| 56 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary64(0x3FF5400000000000ull), 1.328125); |
| 57 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary64(0xBFF5400000000000ull), -1.328125); |
| 58 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary64(0x3ff0000000000000ull), 1.0); |
| 59 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary64(0x0000000000000000ull), 0.0); |
| 60 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary64(0xbff0000000000000ull), -1.0); |
| 61 |
MPT_TEST_EXPECT_EQUAL(mpt::DecodeIEEE754binary64(0x3ff0000000000000ull), 1.0); |
| 62 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary64LE(1.0).GetInt64(), 0x3ff0000000000000ull); |
| 63 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary64BE(1.0).GetInt64(), 0x3ff0000000000000ull); |
| 64 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary64LE(mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0xf0), mpt::as_byte(0x3f)), 1.0); |
| 65 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary64BE(mpt::as_byte(0x3f), mpt::as_byte(0xf0), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00)), 1.0); |
| 66 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary64LE(1.0), IEEE754binary64LE(mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0xf0), mpt::as_byte(0x3f))); |
| 67 |
MPT_TEST_EXPECT_EQUAL(IEEE754binary64BE(1.0), IEEE754binary64BE(mpt::as_byte(0x3f), mpt::as_byte(0xf0), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00), mpt::as_byte(0x00))); |
| 68 |
} |
| 69 |
|
| 70 |
} // namespace floatingpoint |
| 71 |
} // namespace endian |
| 72 |
} // namespace tests |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
} // namespace MPT_INLINE_NS |
| 77 |
} // namespace mpt |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
#endif // MPT_ENDIAN_TESTS_ENDIAN_FLOATINGPOINT_HPP |