24 template <RealConcept T>
41 const auto iter = _data.lower_bound(x_value);
43 if (iter == _data.begin())
45 return static_cast<T
>(iter->second);
47 if (iter == _data.end())
49 const auto prev = std::prev(iter);
50 return static_cast<T
>(prev->second);
52 if (iter->first == x_value)
54 return static_cast<T
>(iter->second);
57 auto prev = std::prev(iter);
58 const auto [x1, y1] = *prev;
59 const auto [x2, y2] = *iter;
61 return static_cast<T
>(y2 * (x_value - x1) / (x2 - x1) + y1 * (x2 - x_value) / (x2 - x1));
66 auto values = _data | std::views::values;
68 const auto max_element =
69 std::ranges::max_element(values, [](
const double a,
const double b) {
return std::abs(a) < std::abs(b); });
71 return max_element != values.end() ? std::abs(*max_element) : 0.0;
74 template <RealConcept T>
79 throw std::invalid_argument(
"Division by zero is not allowed.");
82 std::ranges::for_each(_data | std::views::values, [a](
auto&
value) {
value /=
static_cast<double>(a); });
86 template std::optional<double> InterpSetData::value<double>(
double)
const noexcept;
88 template void InterpSetData::divide<double>(
double);
90 template std::optional<float> InterpSetData::value<float>(
float)
const noexcept;
92 template void InterpSetData::divide<float>(
float);
double max() const noexcept
Retrieves the maximum absolute value in the interpolation set.
void divide(T a)
Divides all y-values in the dataset by a given number.
std::optional< T > value(T x) const noexcept
Retrieves the interpolated value at a given point.
double RealType
Type for real numbers.
Header file for the interpolation of sets of data.