From a81067603cde72701569d42c48efe3cda1e0594a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 14 Jan 2022 16:52:44 +0900 Subject: [PATCH] [gamecode] Mention possibly undefined behavior It seems casting from float/double to [unsigned] int/long when the value doesn't fit is undefined (which would explain the inconsistent results). Mentioning the possibility seems like a good idea should the results for such casts change and cause the tests to fail. --- libs/gamecode/test/test-conv0.c | 4 ++-- libs/gamecode/test/test-conv2.c | 4 ++-- libs/gamecode/test/test-conv4.c | 6 ++---- libs/gamecode/test/test-conv6.c | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/libs/gamecode/test/test-conv0.c b/libs/gamecode/test/test-conv0.c index e6d6b6ad7..f8b0e7b03 100644 --- a/libs/gamecode/test/test-conv0.c +++ b/libs/gamecode/test/test-conv0.c @@ -39,9 +39,9 @@ static pr_ivec4_t int_conv_expect[] = { { ~0, ~0, ~0, 0}, //bool64 { 0, ~0, 0, 0}, //bool64 { 0, 0, 0, 0}, // int - { 1, -1, 0x80000000, 0x80000000}, // float + { 1, -1, 0x80000000, 0x80000000}, // float undef? { 99, 0x80000000, 256, 0x7fffffff}, // long - { 0x80000000, 0x80000000, 1, -1}, // double + { 0x80000000, 0x80000000, 1, -1}, // double undef? { 0, 0, 0, 0}, // uint { 1, 1, 1, 0}, // bool32 { 99, 0x80000000, 256, 0x7fffffff}, // ulong diff --git a/libs/gamecode/test/test-conv2.c b/libs/gamecode/test/test-conv2.c index 654dd4c90..ee87f7531 100644 --- a/libs/gamecode/test/test-conv2.c +++ b/libs/gamecode/test/test-conv2.c @@ -49,10 +49,10 @@ static pr_ivec4_t long_conv_expect[] = { { 5, 0, -5, 0xffffffff}, // int { 0x80000000, 0xffffffff, 0x7fffffff, 0}, { 1, 0, -1, -1}, // float - { 0, 0x80000000, 0, 0x80000000}, + { 0, 0x80000000, 0, 0x80000000}, // undef? { 0, 0, 0, 0}, // long { 0, 0, 0, 0}, - { 0, 0x80000000, 0, 0x80000000}, // double + { 0, 0x80000000, 0, 0x80000000}, // double undef? { 1, 0, -1, -1}, { 5, 0, -5, 0}, // uint { 0x80000000, 0, 0x7fffffff, 0}, diff --git a/libs/gamecode/test/test-conv4.c b/libs/gamecode/test/test-conv4.c index 4accd2ee8..8fc1ec846 100644 --- a/libs/gamecode/test/test-conv4.c +++ b/libs/gamecode/test/test-conv4.c @@ -39,11 +39,9 @@ static pr_ivec4_t uint_conv_expect[] = { { ~0, ~0, ~0, 0}, //bool64 { 0, ~0, 0, 0}, //bool64 { 0, 0, 0, 0}, // int - // why 0? expected 0xfffffff. vv gcc bug? - { 1, 0xffffffff, 0, 0}, // float + { 1, 0xffffffff, 0, 0}, // float undef? { 99, 0x80000000, 256, 0x7fffffff}, // long - // why 0? vv expected 0xfffffff. gcc bug? - { 0, 0, 1, 0xffffffff}, // double + { 0, 0, 1, 0xffffffff}, // double undef? { 0, 0, 0, 0}, // uint { 1, 1, 1, 0}, // bool32 { 99, 0x80000000, 256, 0x7fffffff}, // ulong diff --git a/libs/gamecode/test/test-conv6.c b/libs/gamecode/test/test-conv6.c index a5d4f7881..3e84eeb03 100644 --- a/libs/gamecode/test/test-conv6.c +++ b/libs/gamecode/test/test-conv6.c @@ -49,10 +49,10 @@ static pr_ivec4_t ulong_conv_expect[] = { { 5, 0, -5, 0xffffffff}, // int { 0x80000000, 0xffffffff, 0x7fffffff, 0}, { 1, 0, -1, -1}, // float - { 0, 0, 0, 0x80000000}, + { 0, 0, 0, 0x80000000}, // undef? { 0, 0, 0, 0}, // long { 0, 0, 0, 0}, - { 0, 0, 0, 0x80000000}, // double + { 0, 0, 0, 0x80000000}, // double undef? { 1, 0, -1, -1}, { 5, 0, -5, 0}, // uint { 0x80000000, 0, 0x7fffffff, 0},