mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-01-19 04:22:11 +00:00
Clarify matters of syntax
This commit is contained in:
@@ -1932,8 +1932,17 @@ std::string cpp_dec_float<Digits10, ExponentType, Allocator>::str(std::intmax_t
|
||||
}
|
||||
else if (f & std::ios_base::scientific)
|
||||
++number_of_digits;
|
||||
// Determine the number of elements needed to provide the requested digits from cpp_dec_float<Digits10, ExponentType, Allocator>.
|
||||
const std::size_t number_of_elements = (std::min)(static_cast<std::size_t>(static_cast<std::size_t>(number_of_digits / static_cast<std::intmax_t>(cpp_dec_float_elem_digits10)) + 2u),
|
||||
|
||||
// Determine the number of elements needed to provide the requested
|
||||
// digits from cpp_dec_float<Digits10, ExponentType, Allocator>.
|
||||
const std::intmax_t
|
||||
number_of_elements_signed
|
||||
{
|
||||
(std::max)(static_cast<std::intmax_t>(number_of_digits / static_cast<std::intmax_t>(cpp_dec_float_elem_digits10) + 2),
|
||||
std::intmax_t { INT8_C(0) })
|
||||
};
|
||||
|
||||
const std::size_t number_of_elements = (std::min)(static_cast<std::size_t>(number_of_elements_signed),
|
||||
static_cast<std::size_t>(cpp_dec_float_elem_number));
|
||||
|
||||
// Extract the remaining digits from cpp_dec_float<Digits10, ExponentType, Allocator> after the decimal point.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace local {
|
||||
|
||||
@@ -18,11 +19,17 @@ auto my_stringify_via_top_level_number(const std::streamsize strm_size) -> std::
|
||||
{
|
||||
using float_type = boost::multiprecision::number<BackendType, boost::multiprecision::et_off>;
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
using streamsize_type = std::streamsize;
|
||||
#else
|
||||
using streamsize_type = int;
|
||||
#endif
|
||||
|
||||
float_type x("0.0000000000000000222222222222222");
|
||||
|
||||
std::stringstream strm { };
|
||||
|
||||
strm << std::setprecision(strm_size) << std::fixed;
|
||||
strm << std::setprecision(static_cast<streamsize_type>(strm_size)) << std::fixed;
|
||||
strm << x;
|
||||
|
||||
return strm.str();
|
||||
@@ -33,11 +40,17 @@ auto my_stringify_via_str_and_backend_str(const std::streamsize strm_size) -> st
|
||||
{
|
||||
using float_type = boost::multiprecision::number<BackendType, boost::multiprecision::et_off>;
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
using streamsize_type = std::streamsize;
|
||||
#else
|
||||
using streamsize_type = int;
|
||||
#endif
|
||||
|
||||
float_type x("0.0000000000000000222222222222222");
|
||||
|
||||
std::stringstream strm { };
|
||||
|
||||
strm << std::setprecision(strm_size) << std::fixed;
|
||||
strm << std::setprecision(static_cast<streamsize_type>(strm_size)) << std::fixed;
|
||||
|
||||
return x.str(strm_size, strm.flags());
|
||||
}
|
||||
@@ -45,15 +58,17 @@ auto my_stringify_via_str_and_backend_str(const std::streamsize strm_size) -> st
|
||||
template<typename BackendType>
|
||||
auto test() -> void
|
||||
{
|
||||
BOOST_TEST(my_stringify_via_top_level_number<BackendType>(0) == "0");
|
||||
BOOST_TEST(my_stringify_via_top_level_number<BackendType>(8) == "0.00000000");
|
||||
BOOST_TEST(my_stringify_via_top_level_number<BackendType>(12) == "0.000000000000");
|
||||
BOOST_TEST(my_stringify_via_top_level_number<BackendType>(31) == "0.0000000000000000222222222222222");
|
||||
std::cout << "Testing type of test: " << typeid(BackendType).name() << std::endl;
|
||||
|
||||
BOOST_TEST(my_stringify_via_str_and_backend_str<BackendType>(0) == "0");
|
||||
BOOST_TEST(my_stringify_via_str_and_backend_str<BackendType>(8) == "0.00000000");
|
||||
BOOST_TEST(my_stringify_via_str_and_backend_str<BackendType>(12) == "0.000000000000");
|
||||
BOOST_TEST(my_stringify_via_str_and_backend_str<BackendType>(31) == "0.0000000000000000222222222222222");
|
||||
BOOST_TEST(my_stringify_via_top_level_number<BackendType>(std::streamsize { INT8_C(0) }) == "0");
|
||||
BOOST_TEST(my_stringify_via_top_level_number<BackendType>(std::streamsize { INT8_C(8) }) == "0.00000000");
|
||||
BOOST_TEST(my_stringify_via_top_level_number<BackendType>(std::streamsize { INT8_C(12) }) == "0.000000000000");
|
||||
BOOST_TEST(my_stringify_via_top_level_number<BackendType>(std::streamsize { INT8_C(31) }) == "0.0000000000000000222222222222222");
|
||||
|
||||
BOOST_TEST(my_stringify_via_str_and_backend_str<BackendType>(std::streamsize { INT8_C(0) }) == "0");
|
||||
BOOST_TEST(my_stringify_via_str_and_backend_str<BackendType>(std::streamsize { INT8_C(8) }) == "0.00000000");
|
||||
BOOST_TEST(my_stringify_via_str_and_backend_str<BackendType>(std::streamsize { INT8_C(12) }) == "0.000000000000");
|
||||
BOOST_TEST(my_stringify_via_str_and_backend_str<BackendType>(std::streamsize { INT8_C(31) }) == "0.0000000000000000222222222222222");
|
||||
}
|
||||
|
||||
} // namespace local
|
||||
@@ -62,7 +77,10 @@ auto main() -> int
|
||||
{
|
||||
local::test<boost::multiprecision::cpp_bin_float<32>>();
|
||||
local::test<boost::multiprecision::cpp_dec_float<32>>();
|
||||
local::test<boost::multiprecision::cpp_double_fp_backend<double>>();
|
||||
BOOST_IF_CONSTEXPR(std::numeric_limits<double>::digits >= 53)
|
||||
{
|
||||
local::test<boost::multiprecision::cpp_double_fp_backend<double>>();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user