Skip to content

Commit

Permalink
Merge pull request #1223.
Browse files Browse the repository at this point in the history
Add `QL_CONSTEXPR` macro and avoid some MSVC warnings
  • Loading branch information
lballabio committed Nov 4, 2021
2 parents 6f1f71c + edeeb3f commit 6c6edde
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 13 deletions.
Expand Up @@ -65,7 +65,7 @@ namespace QuantLib {
//calculate payoff discount factor assuming continuous compounding
DiscountFactor discount = riskFreeDiscount(t1);
Real result = 0;
Real minusInf=-std::numeric_limits<Real>::infinity();
QL_CONSTEXPR Real minusInf = -std::numeric_limits<Real>::infinity();

Real y1 = this->y1(payoff->optionType()),
y2 = this->y2(payoff->optionType());
Expand Down
2 changes: 1 addition & 1 deletion ql/math/matrixutilities/svd.cpp
Expand Up @@ -514,7 +514,7 @@ namespace QuantLib {
}

Size SVD::rank() const {
Real eps = QL_EPSILON;
QL_CONSTEXPR Real eps = QL_EPSILON;
Real tol = m_*s_[0]*eps;
Size r = 0;
for (double i : s_) {
Expand Down
2 changes: 1 addition & 1 deletion ql/pricingengines/asian/mc_discr_geom_av_price.cpp
Expand Up @@ -43,7 +43,7 @@ namespace QuantLib {
product *= path.front();
}
// care must be taken not to overflow product
Real maxValue = QL_MAX_REAL;
QL_CONSTEXPR Real maxValue = QL_MAX_REAL;
averagePrice = 1.0;
for (Size i=1; i<n+1; i++) {
Real price = path[i];
Expand Down
2 changes: 1 addition & 1 deletion ql/pricingengines/asian/mc_discr_geom_av_price_heston.cpp
Expand Up @@ -44,7 +44,7 @@ namespace QuantLib {
Size fixings = pastFixings_ + fixingIndices_.size();

// care must be taken not to overflow product
Real maxValue = QL_MAX_REAL;
QL_CONSTEXPR Real maxValue = QL_MAX_REAL;
for (unsigned long fixingIndice : fixingIndices_) {
Real price = path[fixingIndice];
if (product < maxValue/price) {
Expand Down
2 changes: 2 additions & 0 deletions ql/qldefines.hpp
Expand Up @@ -219,8 +219,10 @@
// until we stop supporting Visual C++ 2013
#if defined(QL_PATCH_MSVC_2013)
# define QL_NOEXCEPT
# define QL_CONSTEXPR
#else
# define QL_NOEXCEPT noexcept
# define QL_CONSTEXPR constexpr
#endif


Expand Down
2 changes: 2 additions & 0 deletions ql/qldefines.hpp.cfg
Expand Up @@ -220,8 +220,10 @@
// until we stop supporting Visual C++ 2013
#if defined(QL_PATCH_MSVC_2013)
# define QL_NOEXCEPT
# define QL_CONSTEXPR
#else
# define QL_NOEXCEPT noexcept
# define QL_CONSTEXPR constexpr
#endif


Expand Down
Expand Up @@ -111,7 +111,7 @@ namespace QuantLib {
Brent solver;
solver.setMaxEvaluations(10000);
const Volatility guess = std::sqrt(theta);
const Real accuracy = std::numeric_limits<Real>::epsilon();
QL_CONSTEXPR Real accuracy = std::numeric_limits<Real>::epsilon();

return solver.solve([&](Volatility _v) { return blackValue(payoff.optionType(), strike, fwd,
t, _v, df, npv); },
Expand Down
4 changes: 2 additions & 2 deletions test-suite/array.cpp
Expand Up @@ -192,13 +192,13 @@ void ArrayTest::testArrayFunctions() {
a[i] = std::sin(Real(i))+1.1;
}

const Real exponential = -2.3;
QL_CONSTEXPR Real exponential = -2.3;
const Array p = Pow(a, exponential);
const Array e = Exp(a);
const Array l = Log(a);
const Array s = Sqrt(a);

const Real tol = 10*QL_EPSILON;
QL_CONSTEXPR Real tol = 10*QL_EPSILON;
for (Size i=0; i < a.size(); ++i) {
if (std::fabs(p[i]-std::pow(a[i], exponential)) > tol) {
BOOST_FAIL("Array function test Pow failed");
Expand Down
4 changes: 2 additions & 2 deletions test-suite/cmsspread.cpp
Expand Up @@ -219,9 +219,9 @@ void CmsSpreadTest::testCouponPricing() {
cpn1->setPricer(d.cmsspPricerLn);

#ifndef __FAST_MATH__
const Real eqTol = 100*QL_EPSILON;
QL_CONSTEXPR Real eqTol = 100*QL_EPSILON;
#else
const Real eqTol = 1e-13;
QL_CONSTEXPR Real eqTol = 1e-13;
#endif
BOOST_CHECK_CLOSE(cpn1->rate(), cpn1a->rate() - cpn1b->rate(), eqTol);
cms10y->addFixing(d.refDate, 0.05);
Expand Down
2 changes: 1 addition & 1 deletion test-suite/interpolations.cpp
Expand Up @@ -2191,7 +2191,7 @@ void InterpolationTest::testLagrangeInterpolation() {
0.5130076920869246
};

const Real tol = 50*QL_EPSILON;
QL_CONSTEXPR Real tol = 50*QL_EPSILON;
for (Size i=0; i < 79; ++i) {
const Real xx = -1.0 + i*0.025;
const Real calculated = interpl(xx);
Expand Down
2 changes: 1 addition & 1 deletion test-suite/numericaldifferentiation.cpp
Expand Up @@ -31,7 +31,7 @@ using namespace boost::unit_test_framework;

namespace {
bool isTheSame(Real a, Real b) {
const Real eps = 500*QL_EPSILON;
QL_CONSTEXPR Real eps = 500*QL_EPSILON;

if (std::fabs(b) < QL_EPSILON)
return std::fabs(a) < eps;
Expand Down
4 changes: 2 additions & 2 deletions test-suite/ode.cpp
Expand Up @@ -197,8 +197,8 @@ void OdeTest::testMatrixExponentialOfZero() {

Matrix m(3, 3, 0.0);

const Real tol = 100*QL_EPSILON;
const Time t=1.0;
QL_CONSTEXPR Real tol = 100*QL_EPSILON;
QL_CONSTEXPR Time t=1.0;
const Matrix calculated = Expm(m, t);

for (Size i=0; i < calculated.rows(); ++i) {
Expand Down

0 comments on commit 6c6edde

Please sign in to comment.