mpz_sqrt_if_perfect_square

Niels Möller nisse at lysator.liu.se
Wed Jun 3 21:26:53 CEST 2026


marco.bodrato at tutanota.com writes:

> Ciao,
>
> 3 giu 2026, 05:55 da braintwo at gmail.com:
>
>>> The top limb could be zero, right?
>>>
>> The docs say "The most significant limb of @{@var{s1p}, @var{n}@} must be
>> non-zero."
>> I believe this makes the size of sqrt(u) exactly (n+1)/ 2 for any perfect
>> square.
>>
> I agree.

Could worthy of a comment and/or an ASSERT.

>> I'm was unsure how much I should optimize for an extra memory allocation vs
>> clobbering rop.
>>
> Well, actually an undefined return value was not really a problem IMO. We already have:

I don't have a strong opinion against an undefined value in the
non-square case. It's nice if it can be unchanged in the non-square
case, but that's not worth a lot of allocation overhead.

Regards,
/Niels

-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list