From 02d2ca8ac77e8deaa494199f79624176df6a2b6c Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Wed, 5 Feb 2014 15:26:46 +0800 Subject: [PATCH] Fix and extend *FCAST test in tcctest.c Result of float to unsigned integer conversion is undefined if float is negative. This commit take the absolute value of the float before doing the conversion to unsigned integer and add more float to integer conversion test. --- tests/tcctest.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/tcctest.c b/tests/tcctest.c index d185111..1653927 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1670,7 +1670,7 @@ void prefix ## fcast(type a)\ double da;\ LONG_DOUBLE la;\ int ia;\ - long long lla;\ + long long llia;\ unsigned int ua;\ unsigned long long llua;\ type b;\ @@ -1679,18 +1679,21 @@ void prefix ## fcast(type a)\ la = a;\ printf("ftof: %f %f %Lf\n", fa, da, la);\ ia = (int)a;\ - lla = (long long)a;\ + llia = (long long)a;\ + a = (a >= 0) ? a : -a;\ ua = (unsigned int)a;\ llua = (unsigned long long)a;\ - printf("ftoi: %d %u\n", ia, ua);\ + printf("ftoi: %d %u %lld %llu\n", ia, ua, llia, llua);\ ia = -1234;\ ua = 0x81234500;\ + llia = -0x123456789012345LL;\ + llua = 0xf123456789012345LLU;\ b = ia;\ printf("itof: " fmt "\n", b);\ - b = lla;\ - printf("lltof: " fmt "\n", b);\ b = ua;\ printf("utof: " fmt "\n", b);\ + b = llia;\ + printf("lltof: " fmt "\n", b);\ b = llua;\ printf("ulltof: " fmt "\n", b);\ }\