26#include <ql/errors.hpp>
27#include <ql/math/comparison.hpp>
28#include <ql/types.hpp>
29#include <ql/utilities/null.hpp>
42 enum Operator {
none,
plus,
minus,
multiply,
divide,
max,
min,
pow,
abs,
gtZero,
geqZero,
negate,
exp,
log };
54 template <
class I> Real
operator()(I begin, I end)
const;
55 Real
operator()(
const std::vector<Real>& values)
const {
return operator()(values.begin(), values.end()); }
86 std::vector<CompiledFormula>
args_;
92 if (
x_ != Null<Real>())
94 if (
v_ != Null<Size>()) {
95 QL_REQUIRE((end - begin) >
static_cast<int>(
v_),
96 "CompiledFormula: need value for index " <<
v_ <<
", given values size is " << (end - begin));
101 return args_[0](begin, end) +
args_[1](begin, end);
103 return args_[0](begin, end) -
args_[1](begin, end);
105 return args_[0](begin, end) *
args_[1](begin, end);
107 return args_[0](begin, end) /
args_[1](begin, end);
109 return std::max(
args_[0](begin, end),
args_[1](begin, end));
111 return std::min(
args_[0](begin, end),
args_[1](begin, end));
113 return std::pow(
args_[0](begin, end),
args_[1](begin, end));
115 Real tmp =
args_[0](begin, end);
116 return tmp > 0.0 && !QuantLib::close_enough(tmp, 0.0) ? 1.0 : 0.0;
119 Real tmp =
args_[0](begin, end);
120 return tmp > 0.0 || QuantLib::close_enough(tmp, 0.0) ? 1.0 : 0.0;
123 return std::abs(
args_[0](begin, end));
125 return -
args_[0](begin, end);
127 return std::exp(
args_[0](begin, end));
129 return std::log(
args_[0](begin, end));
131 QL_FAIL(
"CompiledFormula: unknown operator");