1 // Copyright (C) 2009-2013 Free Software Foundation, Inc. 2 // 3 // This file is part of the GNU ISO C++ Library. This library is free 4 // software; you can redistribute it and/or modify it under the 5 // terms of the GNU General Public License as published by the 6 // Free Software Foundation; either version 3, or (at your option) 7 // any later version. 8 9 // This library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 14 // You should have received a copy of the GNU General Public License along 15 // with this library; see the file COPYING3. If not see 16 // <http://www.gnu.org/licenses/>. 17 18 // { dg-require-effective-target dfp } 19 20 // ISO/IEC TR 24733 3.2.2.3 Conversion from integral type (decimal32). 21 // ISO/IEC TR 24733 3.2.3.3 Conversion from integral type (decimal64). 22 // ISO/IEC TR 24733 3.2.4.3 Conversion from integral type (decimal128). 23 24 #include <decimal/decimal> 25 #include <testsuite_hooks.h> 26 27 using namespace std::decimal; 28 29 void conversion_from_integral_p32()30conversion_from_integral_p32 () 31 { 32 bool test __attribute__((unused)) = true; 33 decimal32 d; 34 decimal32 from_si (1); 35 decimal32 from_ui (2U); 36 decimal32 from_sl (3L); 37 decimal32 from_ul (4UL); 38 decimal32 from_sll (5LL); 39 decimal32 from_ull (6ULL); 40 41 d++; VERIFY (from_si == d); 42 d++; VERIFY (from_ui == d); 43 d++; VERIFY (from_sl == d); 44 d++; VERIFY (from_ul == d); 45 d++; VERIFY (from_sll == d); 46 d++; VERIFY (from_ull == d); 47 48 from_si = 7; 49 d++; VERIFY (from_si == d); 50 from_ui = 8U; 51 d++; VERIFY (from_ui == d); 52 from_sl = 9L; 53 d++; VERIFY (from_sl == d); 54 from_ul = 10UL; 55 d++; VERIFY (from_ul == d); 56 from_sll = 11LL; 57 d++; VERIFY (from_sll == d); 58 from_ull = 12ULL; 59 d++; VERIFY (from_ull == d); 60 } 61 62 void conversion_from_integral_m32()63conversion_from_integral_m32 () 64 { 65 bool test __attribute__((unused)) = true; 66 decimal32 d; 67 decimal32 from_si (-1); 68 decimal32 from_sl (-2L); 69 decimal32 from_sll (-3LL); 70 71 d--; VERIFY (from_si == d); 72 d--; VERIFY (from_sl == d); 73 d--; VERIFY (from_sll == d); 74 75 from_si = -4; 76 d--; VERIFY (from_si == d); 77 from_sl = -5L; 78 d--; VERIFY (from_sl == d); 79 from_sll = -6LL; 80 d--; VERIFY (from_sll == d); 81 } 82 83 void conversion_from_integral_p64()84conversion_from_integral_p64 () 85 { 86 bool test __attribute__((unused)) = true; 87 decimal64 d; 88 decimal64 from_si (1); 89 decimal64 from_ui (2U); 90 decimal64 from_sl (3L); 91 decimal64 from_ul (4UL); 92 decimal64 from_sll (5LL); 93 decimal64 from_ull (6ULL); 94 95 d++; VERIFY (from_si == d); 96 d++; VERIFY (from_ui == d); 97 d++; VERIFY (from_sl == d); 98 d++; VERIFY (from_ul == d); 99 d++; VERIFY (from_sll == d); 100 d++; VERIFY (from_ull == d); 101 102 from_si = 7; 103 d++; VERIFY (from_si == d); 104 from_ui = 8U; 105 d++; VERIFY (from_ui == d); 106 from_sl = 9L; 107 d++; VERIFY (from_sl == d); 108 from_ul = 10UL; 109 d++; VERIFY (from_ul == d); 110 from_sll = 11LL; 111 d++; VERIFY (from_sll == d); 112 from_ull = 12ULL; 113 d++; VERIFY (from_ull == d); 114 } 115 116 void conversion_from_integral_m64()117conversion_from_integral_m64 () 118 { 119 bool test __attribute__((unused)) = true; 120 decimal64 d; 121 decimal64 from_si (-1); 122 decimal64 from_sl (-2L); 123 decimal64 from_sll (-3LL); 124 125 d--; VERIFY (from_si == d); 126 d--; VERIFY (from_sl == d); 127 d--; VERIFY (from_sll == d); 128 129 from_si = -4; 130 d--; VERIFY (from_si == d); 131 from_sl = -5L; 132 d--; VERIFY (from_sl == d); 133 from_sll = -6LL; 134 d--; VERIFY (from_sll == d); 135 } 136 137 void conversion_from_integral_p128()138conversion_from_integral_p128 () 139 { 140 bool test __attribute__((unused)) = true; 141 decimal128 d; 142 decimal128 from_si (1); 143 decimal128 from_ui (2U); 144 decimal128 from_sl (3L); 145 decimal128 from_ul (4UL); 146 decimal128 from_sll (5LL); 147 decimal128 from_ull (6ULL); 148 149 d++; VERIFY (from_si == d); 150 d++; VERIFY (from_ui == d); 151 d++; VERIFY (from_sl == d); 152 d++; VERIFY (from_ul == d); 153 d++; VERIFY (from_sll == d); 154 d++; VERIFY (from_ull == d); 155 156 from_si = 7; 157 d++; VERIFY (from_si == d); 158 from_ui = 8U; 159 d++; VERIFY (from_ui == d); 160 from_sl = 9L; 161 d++; VERIFY (from_sl == d); 162 from_ul = 10UL; 163 d++; VERIFY (from_ul == d); 164 from_sll = 11LL; 165 d++; VERIFY (from_sll == d); 166 from_ull = 12ULL; 167 } 168 169 void conversion_from_integral_m128()170conversion_from_integral_m128 () 171 { 172 bool test __attribute__((unused)) = true; 173 decimal128 d; 174 decimal128 from_si (-1); 175 decimal128 from_sl (-2L); 176 decimal128 from_sll (-3LL); 177 178 d--; VERIFY (from_si == d); 179 d--; VERIFY (from_sl == d); 180 d--; VERIFY (from_sll == d); 181 182 from_si = -4; 183 d--; VERIFY (from_si == d); 184 from_sl = -5L; 185 d--; VERIFY (from_sl == d); 186 from_sll = -6LL; 187 d--; VERIFY (from_sll == d); 188 } 189 190 int main()191main () 192 { 193 conversion_from_integral_p32 (); 194 conversion_from_integral_m32 (); 195 conversion_from_integral_p64 (); 196 conversion_from_integral_m64 (); 197 conversion_from_integral_p128 (); 198 conversion_from_integral_m128 (); 199 } 200