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

Add: BinaryInteger/ilog(_:) #77

Open
oscbyspro opened this issue Aug 28, 2024 · 2 comments
Open

Add: BinaryInteger/ilog(_:) #77

oscbyspro opened this issue Aug 28, 2024 · 2 comments
Labels
addition oh, so shiny! brrr such code, much wow

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 28, 2024

BinaryInteger/ilog2() is basically a bit counting operation, which is why it returns Count<IX>. This is awkward when you want the result as an instance of Self. Instead of adding a bunch of overloads, I think it might be better to perform this conversion in an arbitrary base function. The latter offers additional utility and a constant binary base argument should fold into a simple conversion, assuming I add an appropriate fast path.

@oscbyspro oscbyspro added addition oh, so shiny! brrr such code, much wow labels Aug 28, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 28, 2024

I might need a Radix<T> (natural ≥ 2) type so that Nonzero<T.Magnitude> can return a nonoptional result. Hm. Never-mind. Nonzero<T.Magnitude> may be infinite. I would also need Nonzero<Natural<T.Magnitude>>. Meh. Alternatively, I could get the guarantee of Natural<T.Magnitude> from an UnsignedInteger & SystemsInteger constraint.

@oscbyspro oscbyspro changed the title Add: Logarithms for arbitrary bases Add: BinaryInteger/ilog(_:) Aug 28, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 31, 2024

Tangentially, it turns out that the discrete logarithm problem is trivial when the group size is a power of 2. But, everybody already knows that. No dice, but a fun rabbit hole nonetheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! brrr such code, much wow
Projects
None yet
Development

No branches or pull requests

1 participant