Skip to content

Commit

Permalink
Fixes precision loss when adding nested models.
Browse files Browse the repository at this point in the history
The precision loss is resolved by explicitly calling std::setprecision
for float and double parameters when these are streamed/requested as
strings.
  • Loading branch information
hauke76 committed Jul 6, 2020
1 parent 3b4275d commit dadc373
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/sdf/Param.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cctype>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <memory>
#include <optional>
#include <sstream>
Expand Down Expand Up @@ -79,6 +80,20 @@ namespace sdf
return os;
}

template<>
inline std::ostream& operator<<(std::ostream &os, ParamStreamer<double> s)
{
os << std::setprecision(std::numeric_limits<double>::max_digits10) << s.val;
return os;
}

template<>
inline std::ostream& operator<<(std::ostream &os, ParamStreamer<float> s)
{
os << std::setprecision(std::numeric_limits<float>::max_digits10) << s.val;
return os;
}

template<class... Ts>
std::ostream& operator<<(std::ostream& os,
ParamStreamer<std::variant<Ts...>> sv)
Expand Down

0 comments on commit dadc373

Please sign in to comment.