|
26 | 26 | #include <boost/decimal/detail/countl.hpp> |
27 | 27 | #include <boost/decimal/detail/remove_trailing_zeros.hpp> |
28 | 28 | #include <boost/decimal/detail/promotion.hpp> |
29 | | -#include <boost/decimal/detail/quantum_preservation_format.hpp> |
30 | 29 |
|
31 | 30 | #ifndef BOOST_DECIMAL_BUILD_MODULE |
32 | 31 | #include <cstdint> |
@@ -1110,9 +1109,19 @@ constexpr auto to_chars_hex_impl(char* first, char* last, const TargetDecimalTyp |
1110 | 1109 | return to_chars_integer_impl<std::uint32_t>(first, last, static_cast<std::uint32_t>(abs_exp)); |
1111 | 1110 | } |
1112 | 1111 |
|
| 1112 | +#ifdef _MSC_VER |
| 1113 | +# pragma warning(push) |
| 1114 | +# pragma warning(disable: 4702) // Unreachable code |
| 1115 | +#endif |
| 1116 | + |
1113 | 1117 | template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType> |
1114 | 1118 | constexpr auto to_chars_cohort_preserving_scientific(char* first, char* last, const TargetDecimalType& value) noexcept -> to_chars_result |
1115 | 1119 | { |
| 1120 | + BOOST_DECIMAL_IF_CONSTEXPR (detail::is_fast_type_v<TargetDecimalType>) |
| 1121 | + { |
| 1122 | + return {last, std::errc::invalid_argument}; |
| 1123 | + } |
| 1124 | + |
1116 | 1125 | using unsigned_integer = typename TargetDecimalType::significand_type; |
1117 | 1126 |
|
1118 | 1127 | const auto fp = fpclassify(value); |
@@ -1171,11 +1180,6 @@ constexpr auto to_chars_cohort_preserving_scientific(char* first, char* last, co |
1171 | 1180 | return to_chars_integer_impl<std::uint32_t>(first, last, abs_exp); |
1172 | 1181 | } |
1173 | 1182 |
|
1174 | | -#ifdef _MSC_VER |
1175 | | -# pragma warning(push) |
1176 | | -# pragma warning(disable: 4702) // Unreachable code |
1177 | | -#endif |
1178 | | - |
1179 | 1183 | template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType> |
1180 | 1184 | constexpr auto to_chars_impl(char* first, char* last, const TargetDecimalType& value, const chars_format fmt = chars_format::general, const int local_precision = -1) noexcept -> to_chars_result |
1181 | 1185 | { |
@@ -1212,6 +1216,20 @@ constexpr auto to_chars_impl(char* first, char* last, const TargetDecimalType& v |
1212 | 1216 | return to_chars_scientific_impl(first, last, value, fmt); |
1213 | 1217 | case chars_format::hex: |
1214 | 1218 | return to_chars_hex_impl(first, last, value); |
| 1219 | + case chars_format::cohort_preserving_scientific: |
| 1220 | + BOOST_DECIMAL_IF_CONSTEXPR (detail::is_fast_type_v<TargetDecimalType>) |
| 1221 | + { |
| 1222 | + // Fast types have no concept of cohorts |
| 1223 | + return {last, std::errc::invalid_argument}; |
| 1224 | + } |
| 1225 | + |
| 1226 | + if (local_precision != -1) |
| 1227 | + { |
| 1228 | + // Precision and cohort preservation are mutually exclusive options |
| 1229 | + return {last, std::errc::invalid_argument}; |
| 1230 | + } |
| 1231 | + |
| 1232 | + return to_chars_cohort_preserving_scientific(first, last, value); |
1215 | 1233 | // LCOV_EXCL_START |
1216 | 1234 | default: |
1217 | 1235 | BOOST_DECIMAL_UNREACHABLE; |
@@ -1243,34 +1261,6 @@ constexpr auto to_chars_impl(char* first, char* last, const TargetDecimalType& v |
1243 | 1261 | return to_chars_scientific_impl(first, last, value, fmt, local_precision); // LCOV_EXCL_LINE |
1244 | 1262 | } |
1245 | 1263 |
|
1246 | | -// TODO(mborland): Remove once other modes are inplace |
1247 | | -#ifdef _MSC_VER |
1248 | | -# pragma warning(push) |
1249 | | -# pragma warning(disable: 4065) |
1250 | | -#endif |
1251 | | - |
1252 | | -template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType> |
1253 | | -constexpr auto to_chars_impl(char* first, char* last, const TargetDecimalType& value, const chars_format fmt, const quantum_preservation method) noexcept -> to_chars_result |
1254 | | -{ |
1255 | | - // No quantum preservation is the same thing as regular to_chars |
1256 | | - if (method == quantum_preservation::off) |
1257 | | - { |
1258 | | - return to_chars_impl(first, last, value, fmt); |
1259 | | - } |
1260 | | - |
1261 | | - // Sanity check our bounds |
1262 | | - if (BOOST_DECIMAL_UNLIKELY(first >= last)) |
1263 | | - { |
1264 | | - return {last, std::errc::invalid_argument}; |
1265 | | - } |
1266 | | - |
1267 | | - switch (fmt) |
1268 | | - { |
1269 | | - default: |
1270 | | - return to_chars_cohort_preserving_scientific(first, last, value); |
1271 | | - } |
1272 | | -} |
1273 | | - |
1274 | 1264 | #ifdef _MSC_VER |
1275 | 1265 | # pragma warning(pop) |
1276 | 1266 | #endif |
@@ -1300,13 +1290,6 @@ constexpr auto to_chars(char* first, char* last, const TargetDecimalType& value, |
1300 | 1290 | return detail::to_chars_impl(first, last, value, fmt, precision); |
1301 | 1291 | } |
1302 | 1292 |
|
1303 | | -BOOST_DECIMAL_EXPORT template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType> |
1304 | | -constexpr auto to_chars(char* first, char* last, const TargetDecimalType& value, const chars_format fmt, const quantum_preservation method) noexcept -> to_chars_result |
1305 | | -{ |
1306 | | - static_assert(detail::is_ieee_type_v<TargetDecimalType>, "Fast types are automatically normalized, so they have no concept of quantum preservation"); |
1307 | | - return detail::to_chars_impl(first, last, value, fmt, method); |
1308 | | -} |
1309 | | - |
1310 | 1293 | #ifdef BOOST_DECIMAL_HAS_STD_CHARCONV |
1311 | 1294 |
|
1312 | 1295 | BOOST_DECIMAL_EXPORT template <typename DecimalType> |
|
0 commit comments