97 const auto old_unit = fValue.get_unit_key();
98 if (old_unit == _unit)
return true;
100 const auto old_type = gunits->get_type(old_unit);
101 const auto new_type = gunits->get_type(_unit);
102 const bool cross_type = old_type != gunits->kUndef_type && old_type != new_type;
105 if (!fValue.set_unit(_unit))
return false;
106 fError.set_unit(_unit);
107 fErrorLow.set_unit(_unit);
108 fErrorHigh.set_unit(_unit);
115 tkunit converted_value = fValue;
116 if (!converted_value.
set_unit(_unit))
return false;
118 const double error_low = fAsymError ? fErrorLow.
get_value() : fError.get_value();
119 const double error_high = fAsymError ? fErrorHigh.get_value() : fError.get_value();
121 if (error_low < 0. || error_high < 0.) {
122 fValue = converted_value;
124 fErrorLow.set_value(-1., _unit);
125 fErrorHigh.set_value(-1., _unit);
130 const double value = fValue.get_value();
131 tkunit endpoint_low(value - error_low, old_unit);
132 tkunit endpoint_high(value + error_high, old_unit);
133 if (!endpoint_low.
set_unit(_unit) || !endpoint_high.
set_unit(_unit))
return false;
135 const double converted = converted_value.
get_value();
136 const double converted_min = std::min(endpoint_low.
get_value(), endpoint_high.
get_value());
137 const double converted_max = std::max(endpoint_low.
get_value(), endpoint_high.
get_value());
138 const double converted_error_low = converted - converted_min;
139 const double converted_error_high = converted_max - converted;
141 fValue = converted_value;
142 if (converted_error_low == converted_error_high) {
143 fError.set_value(converted_error_low, _unit);
144 fErrorLow.set_value(-1., _unit);
145 fErrorHigh.set_value(-1., _unit);
148 fError.set_value(-1., _unit);
149 fErrorLow.set_value(converted_error_low, _unit);
150 fErrorHigh.set_value(converted_error_high, _unit);
void set_value(const double &_val, const tkstring &_unit="")
set the value and unit from string, if _unit not defined, let in the current unit