27 #include <fmt/format.h> 45 , m_uncertainty(uncertainty) {
47 throw std::invalid_argument(
"Uncertainty can not be negative.");
51 :
Uncertain(val.getValue(), val.getError()) {}
62 return (m_value == other.m_value) && (m_uncertainty == other.m_uncertainty);
69 return Uncertain(m_value + other.m_value, m_uncertainty + other.m_uncertainty);
73 return Uncertain(m_value - other.m_value, m_uncertainty + other.m_uncertainty);
102 std::string value{format_str};
103 auto end = value.find(
'}');
104 std::string val = std::string{
"{" + value.substr(0, end) +
"}"};
106 f.writer().write(val.c_str(), s.
get_value());
107 f.writer().write(
" ± ");
110 format_str += end + 1;
Uncertain operator*(const Uncertain &other) const
bool operator==(const Uncertain &other) const
Uncertain operator*(fptype other) const
Allow int and float multiplies.
fptype get_relative_uncertainty() const
Uncertain(fptype value, fptype uncertainty=0)
Uncertain operator/(const Uncertain &other) const
bool operator!=(const Uncertain &other) const
fptype get_uncertainty() const
Uncertain operator-(const Uncertain &other) const
Uncertain operator/(const fptype &other) const
std::ostream & operator<<(std::ostream &stream, Uncertain value)
Simple << output.
Uncertain operator+(const Uncertain &other) const
Uncertain(const Variable &val)
void format_arg(fmt::BasicFormatter< char > &f, const char *&format_str, const Uncertain &s)
fmt support