1 /* { dg-options "-O0" } */ 2 3 /* N1150 5.1 Conversion between decimal floating types and integer. 4 C99 6.3.1.4(1a) New. */ 5 6 #include "dfp-dbg.h" 7 8 #ifdef __cplusplus 9 #define BOOL bool 10 #else 11 #define BOOL _Bool 12 #endif 13 14 _Decimal32 d32; 15 _Decimal64 d64; 16 _Decimal128 d128; 17 unsigned int ui; 18 unsigned long ul; 19 unsigned long long ull; 20 int si; 21 long sl; 22 long long sll; 23 BOOL b; 24 25 void init_dfp_1(void)26init_dfp_1 (void) 27 { 28 d32 = 456.789df; 29 d64 = 23.456789dd; 30 d128 = 1234.5678dl; 31 } 32 void init_dfp_2(void)33init_dfp_2 (void) 34 { 35 d32 = 1.23df; 36 d64 = -3.4dd; 37 d128 = 0.00003dl; 38 } 39 40 void init_dfp_3(void)41init_dfp_3 (void) 42 { 43 d32 = 0.0DF; 44 d64 = 0.0DD; 45 d128 = 0.0DL; 46 } 47 48 void init_unsigned_int(void)49init_unsigned_int (void) 50 { 51 ui = 987U; 52 ul = 345678UL; 53 ull = 1234567ULL; 54 } 55 56 void init_signed_int(void)57init_signed_int (void) 58 { 59 si = -987; 60 sl = -345678; 61 sll = -1234567; 62 } 63 64 int main()65main () 66 { 67 /* C99 Section 6.7.2 Type specifiers. Type _Bool is 68 mentioned in this section. Conversions between 69 BOOL and DFP types. */ 70 71 /* Decimal float to unsigned integer. */ 72 init_dfp_1 (); 73 74 ui = d32; 75 if (ui != 456U) 76 FAILURE 77 ul = d32; 78 if (ul != 456UL) 79 FAILURE 80 ull = d32; 81 if (ull != 456ULL) 82 FAILURE 83 84 ui = d64; 85 if (ui != 23U) 86 FAILURE 87 ul = d64; 88 if (ul != 23UL) 89 FAILURE 90 ull = d64; 91 if (ull != 23ULL) 92 FAILURE 93 94 ui = d128; 95 if (ui != 1234U) 96 FAILURE 97 ul = d128; 98 if (ul != 1234UL) 99 FAILURE 100 ull = d128; 101 if (ull != 1234ULL) 102 FAILURE 103 104 /* Decimal float to signed integer. */ 105 106 /* Decimal float to BOOL. */ 107 init_dfp_2 (); 108 109 b = d32; 110 if (!b) 111 FAILURE 112 b = d64; 113 if (!b) 114 FAILURE 115 b = d128; 116 if (!b) 117 FAILURE 118 119 /* Unsigned integer to decimal float. */ 120 init_unsigned_int (); 121 122 d32 = ui; 123 if (d32 != 987.0df) 124 FAILURE 125 d32 = ul; 126 if (d32 != 345678.0df) 127 FAILURE 128 d32 = ull; 129 if (d32 != 1234567.df) 130 FAILURE 131 132 d64 = ui; 133 if (d64 != 987.0dd) 134 FAILURE 135 d64 = ul; 136 if (d64 != 345678.0dd) 137 FAILURE 138 d64 = ull; 139 if (d64 != 1234567.dd) 140 FAILURE 141 142 d128 = ui; 143 if (d128 != 987.0dl) 144 FAILURE 145 d128 = ul; 146 if (d128 != 345678.0dl) 147 FAILURE 148 d128 = ull; 149 if (d128 != 1234567.dl) 150 FAILURE 151 152 /* Signed integer to decimal float. */ 153 init_signed_int (); 154 155 d32 = si; 156 if (d32 != -987.0df) 157 FAILURE 158 d32 = sl; 159 if (d32 != -345678.0df) 160 FAILURE 161 d32 = sll; 162 if (d32 != -1234567.df) 163 FAILURE 164 165 d64 = si; 166 if (d64 != -987.0dd) 167 FAILURE 168 d64 = sl; 169 if (d64 != -345678.0dd) 170 FAILURE 171 d64 = sll; 172 if (d64 != -1234567.dd) 173 FAILURE 174 175 d128 = si; 176 if (d128 != -987.0dl) 177 FAILURE 178 d128 = sl; 179 if (d128 != -345678.0dl) 180 FAILURE 181 d128 = sll; 182 if (d128 != -1234567.dl) 183 FAILURE 184 185 /* BOOL to decimal float. */ 186 init_dfp_3 (); 187 188 b = d32; 189 if (b) 190 FAILURE 191 b = d64; 192 if (b) 193 FAILURE 194 b = d128; 195 if (b) 196 FAILURE 197 198 FINISH 199 } 200