-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,46 @@ | ||
// Copyright Matt Borland, 2023 | ||
// Copyright Matt Borland 2023 | ||
// Copyright John Maddock 2023 | ||
// Use, modification and distribution are subject to the | ||
// Boost Software License, Version 1.0. (See accompanying file | ||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// See: https://godbolt.org/z/Ev4ManrsW | ||
|
||
#include <boost/math/special_functions/round.hpp> | ||
#define BOOST_TEST_MAIN | ||
#include <boost/test/unit_test.hpp> | ||
#include <cstdint> | ||
#include "math_unit_test.hpp" | ||
|
||
double x = 9223372036854775807.0; // can't be represented as double, will have a different value at runtime. | ||
int main() | ||
template <typename Real> | ||
void test_llround_near_boundary() | ||
{ | ||
int64_t result = boost::math::llround(x); | ||
CHECK_EQUAL(result, INT64_C(9223372036854775807)); | ||
using std::ldexp; | ||
Real boundary = ldexp(static_cast<Real>(1), std::numeric_limits<long long>::digits); | ||
|
||
return boost::math::test::report_errors(); | ||
Real value; | ||
int i; | ||
|
||
for (value = boundary, i = 0; i < 100; value = boost::math::float_next(value), ++i) | ||
{ | ||
BOOST_CHECK_THROW(boost::math::llround(value), boost::math::rounding_error); | ||
} | ||
for (value = boost::math::float_prior(boundary), i = 0; i < 1000; value = boost::math::float_prior(value), ++i) | ||
{ | ||
BOOST_CHECK_EQUAL(static_cast<Real>(boost::math::llround(value)), boost::math::round(value)); | ||
} | ||
for (value = boost::math::float_prior(-boundary), i = 0; i < 100; value = boost::math::float_prior(value), ++i) | ||
{ | ||
BOOST_CHECK_THROW(boost::math::llround(value), boost::math::rounding_error); | ||
} | ||
for (value = -boundary, i = 0; i < 1000; value = boost::math::float_next(value), ++i) | ||
{ | ||
BOOST_CHECK_EQUAL(static_cast<Real>(boost::math::llround(value)), boost::math::round(value)); | ||
} | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE( test_main ) | ||
{ | ||
test_llround_near_boundary<float>(); | ||
test_llround_near_boundary<double>(); | ||
test_llround_near_boundary<long double>(); | ||
} |