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

Easier working with native numbers #585

Open
dignifiedquire opened this issue Mar 25, 2024 · 5 comments
Open

Easier working with native numbers #585

dignifiedquire opened this issue Mar 25, 2024 · 5 comments

Comments

@dignifiedquire
Copy link
Member

dignifiedquire commented Mar 25, 2024

In my usage with BoxedUint I am really missing comparison and calculations with u32 and u64 at least, currently it is quite inefficient as I have to do the following

let x = make_boxed_uint();
let y = x - BoxedUint::from(4); // today
let y = x - 1u32; // should be easily possible

if x < 128u32 {
  return "small";
}
@tarcieri
Copy link
Member

That would require an impl with i32 as the argument. We don't support i32 for anything except shl/shr currently.

I guess specifically for the case of Add/Sub we could take the absolute value of the argument and if it's negative, switch from Add to Sub or Sub to Add accordingly, before converting the absolute value into a BoxedUint.

Do you want this just for i32 or other types of arguments?

@dignifiedquire
Copy link
Member Author

Sorry my example is bad, I am happy with just u32 and u64 support for this. (Updated the example)

@TitouanReal
Copy link

Would manually writing implementations be the best way to go about this? This is a lot of repetitive implementations.

I just did it locally for multiplying ConstMontyForm with u8, u16, u32, u64 and u128, and it is already 40 Mul implementations, if you want to make it work commutatively and with references (ie &{integer}).

If you do not make it work with &{integer}, the number of implementations is divided by 2.

@tarcieri
Copy link
Member

Here's a start which impls Add for BoxedUint: #650

If that pattern seems acceptable I can do it for Sub and Mul as well.

@TitouanReal
Copy link

Would it be possible to have this for ConstMontyForm too? Right now this is even more cumbersome than for BoxedUint, because one has to go from native numbers to Uint and then to ConstMontyForm.

let a: ConstMontyForm<...> = ...;
let b = a * ConstMontyForm::new(&Uint::from(3u32)); // today
let b = a * 3u32; // should be easily possible

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

3 participants