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

Computing the square of a number #547

Open
afabri opened this issue Apr 6, 2023 · 1 comment
Open

Computing the square of a number #547

afabri opened this issue Apr 6, 2023 · 1 comment

Comments

@afabri
Copy link

afabri commented Apr 6, 2023

I am wondering if there is a function for computing the square of an integer. I ask because GMP has mpn_sqr() .

@ckormanyos
Copy link
Member

If you have a large number of limbs, you can improve efficiencs by computing only half the triad of coefficients and doubling them - or something like that. I believe this reduces the computational complexity.

Every time that i try for it i miss something and multiprecision fails. but I#m really prone to typos and mistakes.

I would almost want to take this on in a GSoC 24 with some other optimizations unless it gets done sooner.

On a practical note, it is a bit harder to see the clean C++ interface to catch many use cases. You could provide a squaring functoin and clients knowing they need a square could use it. internally i think you could see if &left == &right in left * right = result, but I'm not sure if that is robust enough.

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