Skip to content

Commit

Permalink
Fix double/Real consistency for maintaining AAD compatibility (#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Oct 5, 2023
2 parents 2d161c5 + bc12e98 commit 6f30467
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test-suite/libormarketmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void LiborMarketModelTest::testSimpleCovarianceModels() {

for (Size k=0; k<size; ++k) {
Real expected = 0;
if (k>2*t) {
if (static_cast<Real>(k) > 2 * t) {
const Real T = fixingTimes[k];
expected=(a*(T-t)+d)*std::exp(-b*(T-t)) + c;
}
Expand Down
12 changes: 6 additions & 6 deletions test-suite/xoshiro256starstar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ void Xoshiro256StarStarTest::testMeanAndStdDevOfNextReal() {
}
randoms.push_back(next);
}
auto mean = std::accumulate(randoms.begin(), randoms.end(), 0.0) / randoms.size();
auto meanError = std::fabs(0.5 - mean);
Real mean = std::accumulate(randoms.begin(), randoms.end(), Real(0.0)) / randoms.size();
Real meanError = std::fabs(0.5 - mean);
if (meanError > 0.005) {
BOOST_ERROR("Mean " << mean << " for seed 1 is not close to 0.5.");
}
std::vector<double> diff(randoms.size());
std::vector<Real> diff(randoms.size());
std::transform(randoms.begin(), randoms.end(), diff.begin(),
[mean](double x) { return x - mean; });
auto stdDev = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0) / randoms.size();
auto stdDevError = std::fabs(1.0 / 12.0 - stdDev);
[mean](Real x) -> Real { return x - mean; });
Real stdDev = std::inner_product(diff.begin(), diff.end(), diff.begin(), Real(0.0)) / randoms.size();
Real stdDevError = std::fabs(1.0 / 12.0 - stdDev);
if (stdDevError > 0.00005) {
BOOST_ERROR("Standard deviation " << stdDev << " for seed 1 is not close to 1/12.");
}
Expand Down

0 comments on commit 6f30467

Please sign in to comment.