summaryrefslogtreecommitdiffstats
path: root/tests/core/io/test_marshalls.h
diff options
context:
space:
mode:
authorSpartan322 <Megacake1234@gmail.com>2024-11-26 12:56:19 -0500
committerSpartan322 <Megacake1234@gmail.com>2024-11-26 12:56:19 -0500
commite58e18261ea7ed3978146ef8d77a900be2601be3 (patch)
tree79c2a4c34f2d888ff962d76edf474c518d1abdea /tests/core/io/test_marshalls.h
parentc5b1645e60a59c0292c04bece3fdb0715a61afea (diff)
parentd09d82d433b03bb3773fd2a8cc8d6ccc2f8739ce (diff)
downloadredot-engine-e58e18261ea7ed3978146ef8d77a900be2601be3.tar.gz
Merge commit godotengine/godot@d09d82d433b03bb3773fd2a8cc8d6ccc2f8739ce
Diffstat (limited to 'tests/core/io/test_marshalls.h')
-rw-r--r--tests/core/io/test_marshalls.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/core/io/test_marshalls.h b/tests/core/io/test_marshalls.h
index d449f5e754..b506d283a5 100644
--- a/tests/core/io/test_marshalls.h
+++ b/tests/core/io/test_marshalls.h
@@ -92,6 +92,20 @@ TEST_CASE("[Marshalls] Unsigned 64 bit integer decoding") {
CHECK(decode_uint64(arr) == 0x0f123456789abcdef);
}
+TEST_CASE("[Marshalls] Floating point half precision encoding") {
+ uint8_t arr[2];
+
+ // Decimal: 0.33325195
+ // IEEE 754 half-precision binary floating-point format:
+ // sign exponent (5 bits) fraction (10 bits)
+ // 0 01101 0101010101
+ // Hexadecimal: 0x3555
+ unsigned int actual_size = encode_half(0.33325195f, arr);
+ CHECK(actual_size == sizeof(uint16_t));
+ CHECK(arr[0] == 0x55);
+ CHECK(arr[1] == 0x35);
+}
+
TEST_CASE("[Marshalls] Floating point single precision encoding") {
uint8_t arr[4];
@@ -128,6 +142,13 @@ TEST_CASE("[Marshalls] Floating point double precision encoding") {
CHECK(arr[7] == 0x3f);
}
+TEST_CASE("[Marshalls] Floating point half precision decoding") {
+ uint8_t arr[] = { 0x55, 0x35 };
+
+ // See floating point half precision encoding test case for details behind expected values.
+ CHECK(decode_half(arr) == 0.33325195f);
+}
+
TEST_CASE("[Marshalls] Floating point single precision decoding") {
uint8_t arr[] = { 0x00, 0x00, 0x20, 0x3e };