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 split method for uint #365

Open
tcoratger opened this issue Apr 8, 2024 · 1 comment
Open

Add split method for uint #365

tcoratger opened this issue Apr 8, 2024 · 1 comment

Comments

@tcoratger
Copy link
Contributor

Is your feature request related to a problem? Please describe.

In situations like:

it is useful to have a method that splits a uint but this method is not yet available in the implementation.

Describe the solution you'd like

It would therefore be appropriate to implement a method that splits a uint into two equal parts with high and low, based on the model of what is done here

fn high(self) -> T;
fn low(self) -> T;
fn split(self) -> (T, T);

This would allow for example to split a U256 into a high part and a low part.

@prestwich
Copy link
Collaborator

prestwich commented Apr 8, 2024

a few problems in implementing:

  • How would the implementation handle odd numbers of bits like Uint<7, 1> ?
  • How would the implementation handle the edge cases Uint<0, 0> and Uint<1,1>
  • Generic params can't be used in const operations, so we can't declare a function with the appropriate signature
    • fn split(self) -> (Uint<{ BITS.ceil_div(2) }, { LIMBS.ceil_div(2) }>, Uint<{ BITS.floor_div(2) }, { LIMBS.ceil_div(2) }>)
  • We could do it the way to_*e_bytes works and force the user to specify the correct output size, panicking otherwise
    • that would force the user to specify 4 generic params. Seems bad.
    • fn split<const B1: usize, const L1: usize, const B2: usize, const L2: usize>(self) -> (Uint<B1, L1>, Uint<B2, L2>)
  • Why not just use a similar DoubleWord type to the linked code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants