24 template <RealConcept T>
32 const auto iter = _data.lower_bound(
static_cast<double>(x));
34 if (iter == _data.begin())
36 return static_cast<T
>(iter->second);
38 if (iter == _data.end())
40 const auto prev = std::prev(iter);
41 return static_cast<T
>(prev->second);
43 if (iter->first ==
static_cast<double>(x))
45 return static_cast<T
>(iter->second);
48 auto prev = std::prev(iter);
49 const auto [x1, y1] = *prev;
50 const auto [x2, y2] = *iter;
52 return static_cast<T
>(y2 * (x - x1) / (x2 - x1) + y1 * (x2 - x) / (x2 - x1));
57 auto values = _data | std::views::values;
59 const auto max_element =
60 std::ranges::max_element(values, [](
const double a,
const double b) {
return std::abs(a) < std::abs(b); });
62 return max_element != values.end() ? std::abs(*max_element) : 0.0;
65 template <RealConcept T>
70 throw std::invalid_argument(
"Division by zero is not allowed.");
73 std::ranges::for_each(_data | std::views::values, [a](
auto&
value) {
value /=
static_cast<double>(a); });
77 template std::optional<double> InterpSetData::value<double>(
double)
const noexcept;
79 template void InterpSetData::divide<double>(
double);
81 template std::optional<float> InterpSetData::value<float>(
float)
const noexcept;
83 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.
Header file for the interpolation of sets of data.