26#ifndef quantlib_interpolation_hpp
27#define quantlib_interpolation_hpp
64 virtual std::vector<Real>
xValues()
const = 0;
65 virtual std::vector<Real>
yValues()
const = 0;
75 template <
class I1,
class I2>
79 const int requiredPoints = 2)
82 "not enough points to interpolate: at least " <<
84 " required, " <<
static_cast<int>(
xEnd_-
xBegin_)<<
" provided");
89 std::vector<Real>
yValues()
const override {
93#if defined(QL_EXTRA_SAFETY_CHECKS)
98 return (x >= x1 && x <= x2) ||
close(x,x1) ||
close(x,x2);
103 #if defined(QL_EXTRA_SAFETY_CHECKS)
109 else if (x > *(
xEnd_-1))
123 return impl_->value(x);
127 return impl_->primitive(x);
131 return impl_->derivative(x);
135 return impl_->secondDerivative(x);
138 return impl_->xMin();
141 return impl_->xMax();
144 return impl_->isInRange(x);
153 "interpolation range is ["
155 <<
"]: extrapolation at " << x <<
" not allowed");
abstract base class for interpolation implementations
virtual Real secondDerivative(Real) const =0
virtual Real value(Real) const =0
virtual Real xMin() const =0
virtual std::vector< Real > yValues() const =0
virtual Real xMax() const =0
virtual std::vector< Real > xValues() const =0
virtual bool isInRange(Real) const =0
virtual Real derivative(Real) const =0
virtual Real primitive(Real) const =0
basic template implementation
Real xMax() const override
std::vector< Real > xValues() const override
Size locate(Real x) const
std::vector< Real > yValues() const override
templateImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const int requiredPoints=2)
bool isInRange(Real x) const override
Real xMin() const override
base class for 1-D interpolations.
Real secondDerivative(Real x, bool allowExtrapolation=false) const
Real derivative(Real x, bool allowExtrapolation=false) const
~Interpolation() override=default
ext::shared_ptr< Impl > impl_
Real operator()(Real x, bool allowExtrapolation=false) const
Real primitive(Real x, bool allowExtrapolation=false) const
void checkRange(Real x, bool extrapolate) const
bool isInRange(Real x) const
floating-point comparisons
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container
bool close(const Quantity &m1, const Quantity &m2, Size n)