Re: flags in a bitmap
"Ruud H.G. van Tol" <[email protected]> Sat, 5 Jul 2025 17:40:28 +0200
| Newsgroups | gmane.comp.mathematics.pari.devel |
|---|---|
| Message-ID | <[email protected]> |
On 2025-07-04 16:57, Ruud H.G. van Tol wrote: > > On 2025-07-04 16:16, Ruud H.G. van Tol wrote: >> [switched from user to dev] >> >> On 2025-07-04 15:51, Bill Allombert wrote: >>> On Fri, Jul 04, 2025 at 12:38:59PM +0200, Ruud H.G. van Tol wrote: >>>>> ? install(bitset,vWL) >>>>> ? x=2^(2^20); >>>>> ? forprime(p=2,2^20,bitset(~x,p)) >>>>> *** last result computed in 8 ms. >>>>> ? my(S=0);for(i=0,2^20-1,S+=bittest(x,i));S >>>>> %16 = 82025 >>>>> *** last result computed in 159 ms. >>>> That indeed looks good, and I can test it. >>> Great, I have made a GIT branch bill-bitset >>> >>> commit 8632eaf7528554234aaa90d9a503476452cbd736 (HEAD -> >>> bill-bitset, origin/bill-bitset, master) >>> Author: Bill Allombert <[email protected]> >>> Date: Thu Jul 3 23:57:00 2025 +0200 >>> >>> New GP functions bitset, bitclear >> >> Thanks. First (minor) remark: >> >> >> -Help: bitclear(~n,i): clear bit i of n (in place) >> +Help: bitclear(~x,n): clear bit n of x (in place) >> >> -Help: bitset(~n,i): set bit i of n in place >> +Help: bitset(~x,n): set bit n of x in place >> >> >> to align it with bittest, and with the code. > > And of course another: > > diff --git a/src/headers/paridecl.h b/src/headers/paridecl.h > +void bitclear(GEN x, long i); > +void bitset(GEN x, long i); > long bittest(GEN x, long n); > > Those long i's might also want to be n's. > These 3 are less equally worded than I would expect: -Help: bitclear(~x,n): clear bit n of x (in place) =Help: bitflip(~x,n): flip bit n of x in place, assuming x >= 2^n. -Help: bitset(~x,n): set bit n of x in place, assuming x>=2^n. +Help: bitclear(~x,n): clear bit n of x in place, assuming x >= 2^n. =Help: bitflip(~x,n): flip bit n of x in place, assuming x >= 2^n. +Help: bitset(~x,n): set bit n of x in place, assuming x >= 2^n. This looks special to me: ? my(x=2^4); print(x); bitclear(x,4); print(x); 16 Vecsmall([]) ? my(x=2^4); print(x); bitflip(x,4); print(x); 16 Vecsmall([]) as I expected 0. -- Ruud