Skip to content

Commit

Permalink
[core] Use std limits to figure the maximum precision
Browse files Browse the repository at this point in the history
This actually applies for type float and double when converting
to string with Seiscomp::Core::toString.
  • Loading branch information
gempa-jabe committed Nov 2, 2022
1 parent 348311a commit 8c59f27
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions libs/seiscomp/core/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <seiscomp/core/datetime.h>

#include <boost/iostreams/stream.hpp>
#include <limits>
#include <string>
#include <vector>
#include <complex>
Expand Down
28 changes: 26 additions & 2 deletions libs/seiscomp/core/strings.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,31 @@ namespace Core {
template <typename T>
inline std::string toString(const T &v) {
std::ostringstream os;
os << Number<T>(v);
os << v;
return os.str();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<




// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <>
inline std::string toString(const float &v) {
std::ostringstream os;
os << Number<float>(v);
return os.str();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<




// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <>
inline std::string toString(const double &v) {
std::ostringstream os;
os << Number<double>(v);
return os.str();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Expand All @@ -47,7 +71,7 @@ inline std::string toString(const T &v) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename T>
std::ostream &operator<<(std::ostream &ostream, Number<T> n) {
ostream.precision(10);
ostream.precision(std::numeric_limits<T>::max_digits10);
ostream << n.ref;
return ostream;
}
Expand Down

0 comments on commit 8c59f27

Please sign in to comment.