summaryrefslogtreecommitdiffstats
path: root/tests/core/io/test_marshalls.h
diff options
context:
space:
mode:
authorThaddeus Crews <repiteo@outlook.com>2024-11-22 14:54:19 -0600
committerThaddeus Crews <repiteo@outlook.com>2024-11-22 14:54:19 -0600
commitc35e4c41d2dc6ccbc74ddb28d1dcf082468feec9 (patch)
treef03c12c754d6f0446c46b8b01a289e200a9be5d4 /tests/core/io/test_marshalls.h
parentcef0c3548e5eb1c40a1819511cde68de07da9387 (diff)
parenteb86670f94ef505e9b4adc37bc0948a3a5588ed8 (diff)
downloadredot-engine-c35e4c41d2dc6ccbc74ddb28d1dcf082468feec9.tar.gz
Merge pull request #97716 from pafuent/add_half_precision_floating_point_to_stream_peer
Add half precision floating point support to `StreamPeer` and `FileAccess`
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 6716984681..eb92c3f752 100644
--- a/tests/core/io/test_marshalls.h
+++ b/tests/core/io/test_marshalls.h
@@ -90,6 +90,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];
@@ -126,6 +140,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 };