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();
120 auto reverse_limit = [
this, new_type] {
121 if (ftype ==
"half-life" || ftype ==
"decay width")
122 ftype = new_type == gunits->kEnergy ?
"decay width" :
"half-life";
124 if (tag.contains(
";ERR=LT"))
set_info_tag(tag.copy().replace_all(
";ERR=LT",
";ERR=GT"));
125 else if (tag.contains(
";ERR=LE"))
set_info_tag(tag.copy().replace_all(
";ERR=LE",
";ERR=GE"));
126 else if (tag.contains(
";ERR=GT"))
set_info_tag(tag.copy().replace_all(
";ERR=GT",
";ERR=LT"));
127 else if (tag.contains(
";ERR=GE"))
set_info_tag(tag.copy().replace_all(
";ERR=GE",
";ERR=LE"));
130 if (error_low < 0. || error_high < 0.) {
131 fValue = converted_value;
133 fErrorLow.set_value(-1., _unit);
134 fErrorHigh.set_value(-1., _unit);
140 const double value = fValue.get_value();
141 tkunit endpoint_low(value - error_low, old_unit);
142 tkunit endpoint_high(value + error_high, old_unit);
143 if (!endpoint_low.
set_unit(_unit) || !endpoint_high.
set_unit(_unit))
return false;
145 const double converted = converted_value.
get_value();
146 const double converted_min = std::min(endpoint_low.
get_value(), endpoint_high.
get_value());
147 const double converted_max = std::max(endpoint_low.
get_value(), endpoint_high.
get_value());
148 const double converted_error_low = converted - converted_min;
149 const double converted_error_high = converted_max - converted;
151 fValue = converted_value;
152 if (converted_error_low == converted_error_high) {
153 fError.set_value(converted_error_low, _unit);
154 fErrorLow.set_value(-1., _unit);
155 fErrorHigh.set_value(-1., _unit);
158 fError.set_value(-1., _unit);
159 fErrorLow.set_value(converted_error_low, _unit);
160 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