Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/rational.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ BOOST_CXX14_CONSTEXPR void rational<IntType>::normalize()
num /= g;
den /= g;

if (den < -(std::numeric_limits<IntType>::max)()) {
if (std::numeric_limits<IntType>::is_bounded && den < -(std::numeric_limits<IntType>::max)()) {
BOOST_THROW_EXCEPTION(bad_rational("bad rational: non-zero singular denominator"));
}

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(BOOST_TEST_LINK_LIBRARIES Boost::rational)

boost_test(TYPE run SOURCES rational_example.cpp)
boost_test(TYPE run SOURCES rational_test.cpp LINK_LIBRARIES Boost::unit_test_framework)
boost_test(TYPE run SOURCES multiprecision_test.cpp LINK_LIBRARIES Boost::unit_test_framework Boost::multiprecision COMPILE_FEATURES cxx_std_14)
boost_test(TYPE run SOURCES constexpr_test.cpp COMPILE_FEATURES cxx_constexpr)

boost_test(TYPE compile-fail SOURCES expected_fail_01.cpp)
Expand Down
7 changes: 6 additions & 1 deletion test/Jamfile.v2
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#~ Copyright Rene Rivera 2008
#~ Copyright (C) 2025 James E. King III
#~ Distributed under 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)

import testing ;
import-search /boost/config/checks ;
import config : requires ;
Expand All @@ -12,6 +13,10 @@ test-suite rational
: [ run rational_example.cpp ]
[ run rational_test.cpp
/boost/test//boost_unit_test_framework/<link>static ]
[ run multiprecision_test.cpp
/boost/multiprecision//boost_multiprecision
/boost/test//boost_unit_test_framework/<link>static
: : : [ requires cxx14_decltype_auto cxx14_generic_lambdas cxx14_return_type_deduction cxx14_variable_templates cxx14_constexpr ] ]
[ run constexpr_test.cpp : : : [ requires cxx11_constexpr ] ]
[ compile-fail expected_fail_01.cpp ]
[ compile-fail expected_fail_02.cpp ]
Expand Down
21 changes: 21 additions & 0 deletions test/multiprecision_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2025 James E. King III. Distributed under 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)

#define BOOST_TEST_MAIN "Boost::Rational multiprecision unit tests"

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE( issue_27_test )
{
using namespace boost::multiprecision;

// Verify that the check to ensure that the denominator is positive works
// with an arbitrary precision rational.
cpp_rational uut(1, -2);
BOOST_CHECK_EQUAL(numerator(uut), -1);
BOOST_CHECK_EQUAL(denominator(uut), 2);
}