Re: probable bug of "ispower" function in GP: FALSE, apologies!

[email protected]
Newsgroups gmane.comp.mathematics.pari.devel
Message-ID <20230112152231.Horde.UQ73y8QCPZSR1aeR5jQez4J@webmail.math.cnrs.fr>
nice, Karim!


luis
***


Karim Belabas <[email protected]> a écrit :

> * Vincent Lefevre [2023-01-12 12:40]:
>> On 2023-01-12 12:31:09 +0100, [email protected] wrote:
>> > I misunderstood the definition of "ispower"!
>> >
>> > I wanted a function that identify directly if some integer is a power of 2
>>
>> I suppose that you can use something like
>>
>>   ispower(64,,&n)
>>
>> and check that n is 2. But I suppose that for large numbers, this may
>> be inefficient because ispower() will not just check for powers of 2.
>
> Use hammingweight(N) == 1.
>
> Or v = valuation(N,2); N >> v == 1 if you need the exact power. (Will be
> a little slower.)
>
> Cheers,
>
>     K.B.
> --
> Pr Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
> Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
> http://www.math.u-bordeaux.fr/~kbelabas/
> `
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.