mirror of
https://github.com/boostorg/math.git
synced 2026-02-25 16:32:15 +00:00
Simplify and constexperize
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// 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)
|
||||
@@ -6,14 +7,40 @@
|
||||
// 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>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user