| 1 |
/* { dg-options "-O2 -w" } */ |
| 2 |
|
| 3 |
/* N1150 5.1 Conversions from decimal float to integer. */ |
| 4 |
|
| 5 |
/* Test decimal float to integer conversions for values at the limit of |
| 6 |
what will fit into the destination type. This assumes 32-bit int and |
| 7 |
64-bit long long (there's a check for that below). This version tests |
| 8 |
conversions during compilation. */ |
| 9 |
|
| 10 |
#include "dfp-dbg.h" |
| 11 |
|
| 12 |
extern void link_error (void); |
| 13 |
|
| 14 |
void |
| 15 |
doit () |
| 16 |
{ |
| 17 |
_Decimal32 d32; |
| 18 |
_Decimal64 d64; |
| 19 |
_Decimal128 d128; |
| 20 |
int si; |
| 21 |
unsigned int ui; |
| 22 |
long long sll; |
| 23 |
unsigned long long ull; |
| 24 |
|
| 25 |
/* _Decimal32 to int. */ |
| 26 |
|
| 27 |
d32 = 2147483.E3DF; |
| 28 |
si = d32; |
| 29 |
if (si != 2147483000) |
| 30 |
link_error (); |
| 31 |
|
| 32 |
d32 = -2147483.E3DF; |
| 33 |
si = d32; |
| 34 |
if (si != -2147483000) |
| 35 |
link_error (); |
| 36 |
|
| 37 |
/* _Decimal32 to unsigned int. */ |
| 38 |
|
| 39 |
d32 = 4.294967E9DF; |
| 40 |
ui = d32; |
| 41 |
if (ui != 4294967000U) |
| 42 |
link_error (); |
| 43 |
|
| 44 |
/* _Decimal32 to long long. */ |
| 45 |
|
| 46 |
d32 = 922.3372E16DF; |
| 47 |
sll = d32; |
| 48 |
if (sll != 9223372000000000000LL) |
| 49 |
link_error (); |
| 50 |
|
| 51 |
d32 = -92233.72E14DF; |
| 52 |
sll = d32; |
| 53 |
if (sll != -9223372000000000000LL) |
| 54 |
link_error (); |
| 55 |
|
| 56 |
/* _Decimal32 to unsigned long long. */ |
| 57 |
|
| 58 |
d32 = 0.1844674E20DF; |
| 59 |
ull = d32; |
| 60 |
if (ull != 18446740000000000000ULL) |
| 61 |
link_error (); |
| 62 |
|
| 63 |
/* _Decimal64 to int. */ |
| 64 |
|
| 65 |
d64 = 2.147483647E9DD; |
| 66 |
si = d64; |
| 67 |
if (si != 2147483647) |
| 68 |
link_error (); |
| 69 |
|
| 70 |
d64 = -2147483648.DD; |
| 71 |
si = d64; |
| 72 |
if (si != -2147483648) |
| 73 |
link_error (); |
| 74 |
|
| 75 |
/* _Decimal64 to unsigned int. */ |
| 76 |
|
| 77 |
d64 = 42949.67295E5DD; |
| 78 |
ui = d64; |
| 79 |
if (ui != 4294967295) |
| 80 |
link_error (); |
| 81 |
|
| 82 |
/* _Decimal64 to long long. */ |
| 83 |
|
| 84 |
d64 = 9.223372036854775E18DD; |
| 85 |
sll = d64; |
| 86 |
if (sll != 9223372036854775000LL) |
| 87 |
link_error (); |
| 88 |
|
| 89 |
d64 = -92233720.36854775E11DD; |
| 90 |
sll = d64; |
| 91 |
if (sll != -9223372036854775000LL) |
| 92 |
link_error (); |
| 93 |
|
| 94 |
/* _Decimal64 to unsigned long long. */ |
| 95 |
d64 = 1844674407370955.E4DD; |
| 96 |
ull = d64; |
| 97 |
if (ull != 18446744073709550000ULL) |
| 98 |
link_error (); |
| 99 |
|
| 100 |
/* _Decimal128 to int. */ |
| 101 |
|
| 102 |
d128 = 2.147483647E9DL; |
| 103 |
si = d128; |
| 104 |
if (si != 2147483647) |
| 105 |
link_error (); |
| 106 |
|
| 107 |
d128 = -2147483648.DL; |
| 108 |
si = d128; |
| 109 |
if (si != -2147483648) |
| 110 |
link_error (); |
| 111 |
|
| 112 |
/* _Decimal128 to unsigned int. */ |
| 113 |
|
| 114 |
d128 = 4294.967295E6DL; |
| 115 |
ui = d128; |
| 116 |
if (ui != 4294967295) |
| 117 |
link_error (); |
| 118 |
|
| 119 |
/* _Decimal128 to long long. */ |
| 120 |
|
| 121 |
d128 = 9223372036854775807.DL; |
| 122 |
sll = d128; |
| 123 |
if (sll != 9223372036854775807LL) |
| 124 |
link_error (); |
| 125 |
|
| 126 |
d128 = -9.223372036854775808E19DL; |
| 127 |
sll = d128; |
| 128 |
if (sll != -9223372036854775807LL - 1LL) |
| 129 |
link_error (); |
| 130 |
|
| 131 |
/* _Decimal128 to unsigned long long. */ |
| 132 |
d128 = 18446744073709551615.DL; |
| 133 |
ull = d128; |
| 134 |
if (ull != 18446744073709551615ULL) |
| 135 |
link_error (); |
| 136 |
} |
| 137 |
|
| 138 |
int |
| 139 |
main () |
| 140 |
{ |
| 141 |
/* This test assumes 32-bit int and 64-bit long long. */ |
| 142 |
|
| 143 |
if (sizeof (int) != 4 || sizeof (long long) != 8) |
| 144 |
return 0; |
| 145 |
|
| 146 |
doit (); |
| 147 |
return 0; |
| 148 |
} |