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

Strange bit of code in ulong_extras/is_probabprime.c #2168

Open
mhogrefe opened this issue Jan 19, 2025 · 1 comment
Open

Strange bit of code in ulong_extras/is_probabprime.c #2168

mhogrefe opened this issue Jan 19, 2025 · 1 comment

Comments

@mhogrefe
Copy link

mhogrefe commented Jan 19, 2025

Hello,

I'm trying to understand some code in ulong_extras/is_probabprime.c, and I found something unusual. It doesn't seem to be causing any bugs, so either I'm misunderstanding something, or the code is never executed, or it's executed but (unexpectedly?) works.

In the code for n_is_probabprime_lucas, on line 425, n_mulmod_precomp is being called with ninv, which is a ulong created by n_preinvert_limb. But typically n_mulmod_precomp is called with a double generated by n_precompute_inverse instead. That double is typically between 0 and 1, so it's strange that it's cast from a ulong in this case.

Compare the code for n_is_probabprime_fibonacci, on line 258, where n_precompute_inverse is paired with n_mulmod_precomp and n_preinvert_limb with n_mulmod2_preinv, as expected.

Is this intentional?

Thanks,
Mikhail Hogrefe

@albinahlback
Copy link
Collaborator

Indeed, it very much looks like a bug. However, we do get code coverage there.

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

No branches or pull requests

2 participants