Skip to content

Number_types: add regression test for to_interval(cpp_int) with large values#9410

Open
RajdeepKushwaha5 wants to merge 1 commit intoCGAL:mainfrom
RajdeepKushwaha5:fix/to-interval-cpp-int-large
Open

Number_types: add regression test for to_interval(cpp_int) with large values#9410
RajdeepKushwaha5 wants to merge 1 commit intoCGAL:mainfrom
RajdeepKushwaha5:fix/to-interval-cpp-int-large

Conversation

@RajdeepKushwaha5
Copy link
Copy Markdown
Contributor

Summary of Changes

Add a regression test for #5990.

to_interval(cpp_int) used to throw "Cannot convert a non-finite number to an integer" for values whose double conversion overflows to infinity (e.g. 2^10000). The old implementation in RET_boost_mp_base::To_interval called x.compare(double), which Boost.Multiprecision implements via convert_to<number>, failing on ±infinity.

The fix (integer specialization dispatching to Boost_MP_internal::to_interval, using bit-level extraction) is already in main. This PR adds the missing regression test to ensure it does not regress, and closes the issue.

Test cases: 2^10000, -2^10000, 2^1024 (just above DBL_MAX), 2^52, 2^100, 0.

Release Management

  • Affected package(s): Number_types
  • Issue(s) solved (if any): fix Broken to_interval(cpp_int) for large numbers #5990
  • License and copyright ownership: I (Rajdeep Singh Kushwaha) hereby grant CGAL the non-exclusive right to use the code contributed in this PR under the terms of any open-source license used by CGAL.

Copilot AI review requested due to automatic review settings April 1, 2026 17:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a regression test to ensure CGAL::to_interval(boost::multiprecision::cpp_int) correctly handles very large integer values whose double conversion would overflow to ±infinity (issue #5990), preventing reintroduction of the prior exception-throwing behavior.

Changes:

  • Add a new single-source test covering large positive/negative cpp_int values and some exactly representable cases.
  • Register the new test executable in the Number_types test CMakeLists.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Number_types/test/Number_types/to_interval_cpp_int_large.cpp New regression test for to_interval(cpp_int) on huge magnitudes (incl. ±2^10000).
Number_types/test/Number_types/CMakeLists.txt Builds the new regression test as part of the Number_types test suite.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Number_types/test/Number_types/to_interval_cpp_int_large.cpp Outdated
… values

Add a dedicated test that exercises CGAL::to_interval() on
boost::multiprecision::cpp_int values whose double conversion
overflows to infinity (2^10000, 2^1024, -2^10000), as well as
well-behaved values (2^52, 2^100, 0).

The old implementation in RET_boost_mp_base::To_interval called
x.compare(double), which Boost.MP implements via convert_to<number>,
throwing 'Cannot convert a non-finite number to an integer' when
the double is ±infinity.  The fix (integer specialization dispatching
to Boost_MP_internal::to_interval, using bit-level extraction) is
already in place; this test ensures it does not regress.

Closes CGAL#5990
@RajdeepKushwaha5 RajdeepKushwaha5 force-pushed the fix/to-interval-cpp-int-large branch from 08ea260 to 5e8873d Compare April 1, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken to_interval(cpp_int) for large numbers

2 participants