|
| 1 | +// Copyright 2023 Matt Borland |
| 2 | +// Distributed under the Boost Software License, Version 1.0. |
| 3 | +// https://www.boost.org/LICENSE_1_0.txt |
| 4 | + |
| 5 | +#include <boost/decimal.hpp> |
| 6 | +#include <boost/core/lightweight_test.hpp> |
| 7 | + |
| 8 | +using namespace boost::decimal; |
| 9 | + |
| 10 | +#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) && __has_include(<format>) && !defined(BOOST_DECIMAL_DISABLE_CLIB) |
| 11 | + |
| 12 | +#include <format> |
| 13 | + |
| 14 | +template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T> |
| 15 | +void test() |
| 16 | +{ |
| 17 | +/* |
| 18 | + BOOST_TEST_EQ(std::format("{}", T{1}), "1"); |
| 19 | + BOOST_TEST_EQ(std::format("{}", T{10}), "1e+01"); |
| 20 | + BOOST_TEST_EQ(std::format("{}", T{100}), "1e+02"); |
| 21 | + BOOST_TEST_EQ(std::format("{}", T{1000}), "1e+03"); |
| 22 | + BOOST_TEST_EQ(std::format("{}", T{10000}), "1e+04"); |
| 23 | + BOOST_TEST_EQ(std::format("{}", T{210000}), "2.1e+05"); |
| 24 | + BOOST_TEST_EQ(std::format("{}", T{2100000}), "2.1e+06"); |
| 25 | + BOOST_TEST_EQ(std::format("{}", T{21, 6, true}), "-2.1e+07"); |
| 26 | + BOOST_TEST_EQ(std::format("{}", T{211, 6, true}), "-2.11e+08"); |
| 27 | + BOOST_TEST_EQ(std::format("{}", T{2111, 6, true}), "-2.111e+09"); |
| 28 | +
|
| 29 | + BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::infinity()), "inf"); |
| 30 | + BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::infinity()), "-inf"); |
| 31 | + BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::quiet_NaN()), "nan"); |
| 32 | + BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::quiet_NaN()), "-nan(ind)"); |
| 33 | + BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::signaling_NaN()), "nan(snan)"); |
| 34 | + BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::signaling_NaN()), "-nan(snan)"); |
| 35 | + */ |
| 36 | + |
| 37 | + constexpr const char* fmt_string = "{}"; |
| 38 | + |
| 39 | + BOOST_TEST_EQ(std::format(fmt_string, 1.0), "1"); |
| 40 | + BOOST_TEST_EQ(std::format(fmt_string, T{1}), "1"); |
| 41 | +} |
| 42 | + |
| 43 | +int main() |
| 44 | +{ |
| 45 | + test<decimal32>(); |
| 46 | + //test<decimal64>(); |
| 47 | + //test<decimal128>(); |
| 48 | + |
| 49 | + return boost::report_errors(); |
| 50 | +} |
| 51 | + |
| 52 | +#else |
| 53 | + |
| 54 | +int main() |
| 55 | +{ |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +#endif |
0 commit comments