25#ifndef __OSTREAM_TOOLS_HPP__
26#define __OSTREAM_TOOLS_HPP__
48inline std::string boolstr(
bool b__)
63 hbar(
int w__,
char c__)
82 char prev = out.fill();
83 out << std::setfill(b.c()) << std::setw(b.w()) << b.c() << std::setfill(prev);
93 ffmt(
int w__,
int p__)
112 out.precision(f.p());
114 out.setf(std::ios_base::fixed, std::ios_base::floatfield);
121operator<<(std::ostream& out, std::vector<T>& v)
127 for (
size_t i = 0; i < v.size() - 1; i++) {
130 out << v.back() <<
"}";
140 double abs_val = std::abs(val);
142 if (precision == -1) {
145 }
else if (abs_val > 1e-14) {
146 precision = int(-std::log(abs_val) / std::log(10.0)) + 7;
148 return std::string(
"0.0");
152 std::stringstream fmt;
153 fmt <<
"%." << precision <<
"f";
155 int len = snprintf(buf, 100, fmt.str().c_str(), val);
156 for (
int i = len - 1; i >= 1; i--) {
157 if (buf[i] ==
'0' && buf[i - 1] ==
'0') {
163 return std::string(buf);
166template <
typename T,
typename OUT>
167inline void print_checksum(std::string label__, T value__, OUT&& out__)
169 out__ <<
"checksum(" << label__ <<
") : " << ffmt(16, 8) << value__ << std::endl;
172template <
typename OUT>
173inline void print_hash(std::string label__,
unsigned long long int hash__, OUT&& out__)
175 out__ <<
"hashsum(" << label__ <<
") : " << std::hex << hash__ << std::endl;
Floating-point formatting (precision and width).
Namespace of the SIRIUS library.
std::ostream & operator<<(std::ostream &out, hbar &&b)
Inject horisontal bar to ostream.
std::string double_to_string(double val, int precision=-1)
Convert double to a string with a given precision.