-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_add.cpp
More file actions
51 lines (37 loc) · 2.05 KB
/
test_add.cpp
File metadata and controls
51 lines (37 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/decimal.hpp>
#include <boost/core/lightweight_test.hpp>
#include "test_harness.hpp"
template <typename T>
void test_edges(const char* lhs_str, const char* rhs_str, const char* res_str, const boost::decimal::rounding_mode round)
{
const auto current_round {boost::decimal::fesetround(round)};
BOOST_TEST(current_round == round);
const T lhs {lhs_str};
const T rhs {rhs_str};
const T expected_res {res_str};
const T res {lhs + rhs};
BOOST_TEST_EQ(res, expected_res);
}
int main()
{
#ifndef BOOST_DECIMAL_NO_CONSTEVAL_DETECTION
std::cerr << std::setprecision(std::numeric_limits<boost::decimal::decimal128_t>::max_digits10);
test_edges<boost::decimal::decimal64_t>("1E16", "-0.51", "9999999999999999", boost::decimal::rounding_mode::fe_dec_to_nearest);
test_edges<boost::decimal::decimal128_t>("1E34", "-0.51", "9999999999999999999999999999999999", boost::decimal::rounding_mode::fe_dec_to_nearest);
#endif
test_two_arg_harness("dectest0/add0.decTest", "add", [](const auto x, const auto y) { return x + y; });
test_two_arg_harness("dectest0/inexact0.decTest", "add", [](const auto x, const auto y) { return x + y; });
// Requires rounding-mode changes
#ifndef BOOST_DECIMAL_NO_CONSTEVAL_DETECTION
boost::decimal::fesetround(boost::decimal::rounding_mode::fe_dec_default);
std::cerr << std::setprecision(std::numeric_limits<boost::decimal::decimal64_t>::max_digits10);
test_two_arg_harness<true>("dectest/ddAdd.decTest", "add", [](const auto x, const auto y) { return x + y; });
boost::decimal::fesetround(boost::decimal::rounding_mode::fe_dec_default);
std::cerr << std::setprecision(std::numeric_limits<boost::decimal::decimal128_t>::max_digits10);
test_two_arg_harness<true>("dectest/dqAdd.decTest", "add", [](const auto x, const auto y) { return x + y; });
#endif // BOOST_DECIMAL_NO_CONSTEVAL_DETECTION
return boost::report_errors();
}