14 std::floating_point
auto value,
17 int n = print(buf.data(), buf.size(), fmt, precision, value);
18 assert((
size_t)n < buf.size());
19 return {buf.data(), (size_t)n};
23template <std::
floating_po
int F>
26 int precision = std::numeric_limits<F>::max_digits10) {
27 auto begin = buf.data();
28 if (!std::signbit(value))
30 auto [end, _] = std::to_chars(begin, buf.data() + buf.size(), value,
31 std::chars_format::scientific, precision);
32 return std::string_view{buf.data(), end};
35#pragma message "Using snprintf as a fallback to replace std::to_chars"
37inline std::string_view
39 int precision = std::numeric_limits<double>::max_digits10) {
43inline std::string_view
45 int precision = std::numeric_limits<float>::max_digits10) {
49 auto &buf,
long double value,
50 int precision = std::numeric_limits<long double>::max_digits10) {
56#ifdef ALPAQA_WITH_QUAD_PRECISION
59 int precision = std::numeric_limits<__float128>::max_digits10) {
65template <std::
floating_po
int F>
67 std::array<char, 64> buf;
71template <std::
floating_po
int F>
76template <std::
floating_po
int F>
77void print_elem(
auto &buf, std::complex<F> value, std::ostream &os) {
83std::ostream &
print_csv_impl(std::ostream &os,
const T &M, std::string_view sep,
84 std::string_view begin, std::string_view end) {
85 std::array<char, 64> buf;
88 for (
decltype(M.rows()) r{}; r < M.rows(); ++r) {
90 if (r != M.rows() - 1)
95 for (
decltype(M.rows()) r{}; r < M.rows(); ++r) {
97 for (
decltype(M.cols()) c{}; c < M.cols(); ++c) {
99 if (c != M.cols() - 1)
110 std::string_view end) {
112 return print_csv_impl<T>(os, M,
" ",
"[",
"]") << end;
115 std::array<char, 64> buf;
116 for (
decltype(M.rows()) r{}; r < M.rows(); ++r) {
117 for (
decltype(M.cols()) c{}; c < M.cols(); ++c) {
121 if (r != M.rows() - 1)
124 return os <<
']' << end;
130 std::string_view end) {
132 return print_csv_impl<T>(os, M,
", ",
"[",
"]") << end;
135 std::array<char, 64> buf;
136 for (
decltype(M.rows()) r{}; r < M.rows(); ++r) {
137 for (
decltype(M.cols()) c{}; c < M.cols(); ++c) {
141 if (r != M.rows() - 1)
144 return os <<
"]]" << end;
std::string_view float_to_str_vw_snprintf(auto &&print, auto &buf, std::floating_point auto value, int precision, const char *fmt)
std::ostream & print_matlab_impl(std::ostream &os, const T &M, std::string_view end)
std::ostream & print_python_impl(std::ostream &os, const T &M, std::string_view end)
std::string_view float_to_str_vw(auto &buf, double value, int precision=std::numeric_limits< double >::max_digits10)
void print_elem(auto &buf, F value, std::ostream &os)
std::string float_to_str(F value, int precision)
std::ostream & print_csv_impl(std::ostream &os, const T &M, std::string_view sep, std::string_view begin, std::string_view end)