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

Convert BigNum to/from integer types #80

Open
olehmisar opened this issue Dec 18, 2024 · 5 comments
Open

Convert BigNum to/from integer types #80

olehmisar opened this issue Dec 18, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@olehmisar
Copy link
Contributor

Problem

Need to convert BigNum to/from U128 or u8, u16, u32, u64.

Happy Case

Add BigNum::from(x: U128) and U128::from(x: BigNum) via From trait. An error should be thrown if the conversion is invalid (number is too big/too small).

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

Blocker

Blocker Context

No response

Would you like to submit a PR for this Issue?

Maybe

Support Needs

IDK how to convert, so if someone can explain in words/pseudocode, i can submit a PR

@olehmisar olehmisar added the enhancement New feature or request label Dec 18, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Dec 18, 2024
@kashbrti
Copy link
Contributor

Hi Oleh, I'm currently writing a from_field method for bignum which should help with this. will send you the PR when it's ready. Other than U128 this should all be pretty straightforward, given bignum limbs are 120-bits long. So for all the types you could just make a field element out of them and create a zero array with your field element in index 0

@olehmisar
Copy link
Contributor Author

Why a from_field method instead of From::from trait impl?

@kashbrti
Copy link
Contributor

that's what I meant. I'm writing an impl for std::convert::From<Field> for bignum. The rest should be quite straightforward with the field conversion in hand.

@olehmisar
Copy link
Contributor Author

Good. I specifically need U128 tbh. But it should be convertible using U128::to_integer().into::().

Any chance you can get the conversion from BigNum to Field implemented as well?

@kashbrti
Copy link
Contributor

#87
here's the PR adding the from Field method. It's still WIP, but the logic should be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants