mirror of
https://github.com/boostorg/integer.git
synced 2025-07-29 12:17:13 +02:00
Fixed incorrect loop termination in lcm_range.
lcm_range used to incorrectly terminate on value of 1. Instead, it should terminate on 0 since any further elements of the range no longer affect the result of the function. Also, added tests for the gcd_range and lcm_range functions verifying that they terminate their loops at the correct points.
This commit is contained in:
@ -542,6 +542,15 @@ void variadics()
|
||||
BOOST_TEST_EQ(boost::integer::gcd_range(i, i + 4).second, i + 4);
|
||||
BOOST_TEST_EQ(boost::integer::lcm_range(i, i + 4).first, 11704);
|
||||
BOOST_TEST_EQ(boost::integer::lcm_range(i, i + 4).second, i + 4);
|
||||
|
||||
unsigned i_gcd_unity[] = { 44, 56, 1, 88 };
|
||||
BOOST_TEST_EQ(boost::integer::gcd_range(i_gcd_unity, i_gcd_unity + 4).first, 1);
|
||||
BOOST_TEST_EQ(boost::integer::gcd_range(i_gcd_unity, i_gcd_unity + 4).second, i_gcd_unity + 3);
|
||||
|
||||
unsigned i_lcm_unity[] = { 44, 56, 0, 88 };
|
||||
BOOST_TEST_EQ(boost::integer::lcm_range(i_lcm_unity, i_lcm_unity + 4).first, 0);
|
||||
BOOST_TEST_EQ(boost::integer::lcm_range(i_lcm_unity, i_lcm_unity + 4).second, i_lcm_unity + 3);
|
||||
|
||||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
BOOST_TEST_EQ(boost::integer::gcd(i[0], i[1], i[2], i[3]), 4);
|
||||
BOOST_TEST_EQ(boost::integer::lcm(i[0], i[1], i[2], i[3]), 11704);
|
||||
|
Reference in New Issue
Block a user