Skip to content

Commit a9f3040

Browse files
committed
Better force runtime evaluation
1 parent 695741f commit a9f3040

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

test/github_issue_1112.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
#include <boost/decimal.hpp>
88
#include <boost/core/lightweight_test.hpp>
9+
#include <random>
10+
11+
static std::mt19937_64 rng(42);
12+
std::uniform_int_distribution<> dist(-1, -1);
913

1014
using namespace boost::decimal;
1115

@@ -23,7 +27,7 @@ void test_rounding_up()
2327
const auto mode {boost::decimal::fesetround(rounding_mode::fe_dec_upward)};
2428
if (mode != rounding_mode::fe_dec_default)
2529
{
26-
const T value {2325, -1}; // The result will be wrong if computed at compile time
30+
const T value {2325, dist(rng)}; // The result will be wrong if computed at compile time
2731
const auto dec_res {static_cast<int>(nearbyint(value))};
2832
BOOST_TEST_EQ(dec_res, 233);
2933
}
@@ -35,7 +39,7 @@ void test_rounding_down()
3539
const auto mode {boost::decimal::fesetround(rounding_mode::fe_dec_downward)};
3640
if (mode != rounding_mode::fe_dec_default)
3741
{
38-
const T value {2325, -1}; // The result will be wrong if computed at compile time
42+
const T value {2325, dist(rng)}; // The result will be wrong if computed at compile time
3943
const auto dec_res {static_cast<int>(nearbyint(value))};
4044
BOOST_TEST_EQ(dec_res, 232);
4145
}

0 commit comments

Comments
 (0)