Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCD fails on cpp_int #370

Closed
danston opened this issue Sep 20, 2021 · 3 comments · Fixed by #372
Closed

GCD fails on cpp_int #370

danston opened this issue Sep 20, 2021 · 3 comments · Fixed by #372

Comments

@danston
Copy link

danston commented Sep 20, 2021

I am having an issue with calling gcd on certain cpp_int numbers for several examples in CGAL. I have created a minimal example here.

I have tested it on macOS x86_64 and Linux platforms (both clang and gcc) and, in both cases, the gcd runs forever. To be more precise, in misc.hpp inside eval_gcd_lehmer there is a call to divide_subtract where we enter a while loop but we never exit this loop. After some checking, it seems like the issue was introduced somewhere in-between versions 1.75 and 1.76 of boost because 1.75 works correctly while 1.76 fails. The commit

commit 4f8e0055acc1ef48a2845202a7d87a5ab712c0f8
Author: jzmaddock <john@johnmaddock.co.uk>
Date:   Wed Jul 15 18:15:59 2020 +0100

    GCD: Add double digit Lehmer's algorithm for platforms with synthetic double_limb_type.

 include/boost/multiprecision/cpp_int/misc.hpp | 337 ++++++++++++++++----------
 test/Jamfile.v2                               |   2 +-
 test/test_gcd.cpp                             | 118 +++++++++
 3 files changed, 322 insertions(+), 135 deletions(-)
 create mode 100644 test/test_gcd.cpp

seems to introduce this issue. With the previous commit 981aee54dc2e1aec2d752bb188d9bf6f9d4af0a3 it works correctly.

It would be nice if someone from the authors could have a look and tell me if it is indeed a bug. Thank you!

@jzmaddock
Copy link
Collaborator

Anything that goes into an infinite loop is most certainly a bug. Will look into it shortly.

@afabri
Copy link

afabri commented Sep 25, 2021

Hi @jzmaddock. Note that I could not reproduce the bug with VC++ on Windows. Just in case this was your platform. To me this seems a serious bug, as the gcd is computed several times in each arithmetic operation.

@jzmaddock
Copy link
Collaborator

Confirmed, I just don't see the bug yet.

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 a pull request may close this issue.

3 participants