About sqrt_exact...

marco.bodrato at tutanota.com marco.bodrato at tutanota.com
Thu Jul 23 12:01:00 CEST 2026


Ciao,
20 lug 2026, 16:45 da marco.bodrato at tutanota.com:

>> But a lot of work is still needed, because:
>>  - the code passes "make check" and also some deeper testing, but... it is not completely correct, there are some possible corner cases that are not handled yet;
>>
> Meanwhile, I added a test that my code does not pass ;-)
>
At last, a version of the code that should be always correct.
There aren't corner cases that I'm aware of and that are not handled.
It passes all the tests I'm able to produce.
It works with divappr, or with the classical _div_ interface,
with the former it's slightly faster. 

> The problem is: we compute some binary digits from above and some from below.
> On both ends there is a small uncertainty,
>
...
> A possible strategy to solve this is to detect that kind of corner cases (easy) and handle it with some special code (Try one of the two alternatives, square and check, if wrong, try the other alternative, square again, if wrong again, then return "non square"), but I did not implement it yet. The average time should not be affected.
>
Basically that's what I implemented: in some rare cases try two possible answers. With random input it simply never happens.
It make mpn_perfect_square_p faster, but I'm still not sure if I should push it to the repository.
Ĝis,
m
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqrt_exact.diff
Type: text/x-patch
Size: 15219 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20260723/1738e467/attachment.bin>


More information about the gmp-devel mailing list