Skip to content

MaybeResize for Uint #1275

Description

@kayabaNerve

I open this as an issue as I'm sure it'll need discussion.

Problem:

I need 1 << x where x is ~256-2000, but variable and specified by the caller. I want either:

  • The caller to pass me T = U2048
  • The caller to pass me T = BoxedUint

My issue is if I get T = BoxedUint, I cannot get a 2048-bit BoxedUint without using BoxedUint::one_with_precision, Resize, or BoxedUint::one_like. The first two are specific to BoxedUint. The third is portable with Uint, but would require the caller pass in one_shl_x so that I had the value to 'be like'.

Ideally, I'd have a MaybeResize::resize(One::one(), x) which for fixed types, does nothing, but for BoxedUint, does call BoxedUint::resize.

Are we fine with MaybeResize as a complement to Resize for this purpose? Is there some function I'm missing? Should we instead have One::one_with_precision?

As an absolute hack, I can simply have an RNG which always outputs 0 and abuse RandomBits for this today. As an oddity, RandomBits::try_random_bits_with_precision appears to be the only trait method today which is implemented for both Uint and BoxedUint, while supporting a precision argument (which is discarded if inapplicable). That at least suggests precedent for this...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions