History

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.

Thomas Preud'homme committed 12 years ago

Commit 02d2ca81 parent 17314a11 file · +8 −5Browse files

Unified · Split

tests/tcctest.c+8−5
@@ -1670,7 +1670,7 @@ void prefix ## fcast(type a)\ · 1669 unmodified lines
1670 double da;\1670 double da;\
1671 LONG_DOUBLE la;\1671 LONG_DOUBLE la;\
1672 int ia;\1672 int ia;\
1673 long long lla;\1673 long long llia;\
1674 unsigned int ua;\1674 unsigned int ua;\
1675 unsigned long long llua;\1675 unsigned long long llua;\
1676 type b;\1676 type b;\
@@ -1679,18 +1679,21 @@ void prefix ## fcast(type a)\ · 2 unmodified lines
1679 la = a;\1679 la = a;\
1680 printf("ftof: %f %f %Lf\n", fa, da, la);\1680 printf("ftof: %f %f %Lf\n", fa, da, la);\
1681 ia = (int)a;\1681 ia = (int)a;\
1682 lla = (long long)a;\1682 llia = (long long)a;\
1683 a = (a >= 0) ? a : -a;\
1683 ua = (unsigned int)a;\1684 ua = (unsigned int)a;\
1684 llua = (unsigned long long)a;\1685 llua = (unsigned long long)a;\
1685 printf("ftoi: %d %u\n", ia, ua);\1686 printf("ftoi: %d %u %lld %llu\n", ia, ua, llia, llua);\
1686 ia = -1234;\1687 ia = -1234;\
1687 ua = 0x81234500;\1688 ua = 0x81234500;\
1689 llia = -0x123456789012345LL;\
1690 llua = 0xf123456789012345LLU;\
1688 b = ia;\1691 b = ia;\
1689 printf("itof: " fmt "\n", b);\1692 printf("itof: " fmt "\n", b);\
1690 b = lla;\
1691 printf("lltof: " fmt "\n", b);\
1692 b = ua;\1693 b = ua;\
1693 printf("utof: " fmt "\n", b);\1694 printf("utof: " fmt "\n", b);\
1695 b = llia;\
1696 printf("lltof: " fmt "\n", b);\
1694 b = llua;\1697 b = llua;\
1695 printf("ulltof: " fmt "\n", b);\1698 printf("ulltof: " fmt "\n", b);\
1696}\1699}\

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t