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

[uint] Better constant support #585

Open
uint opened this issue Sep 2, 2021 · 4 comments
Open

[uint] Better constant support #585

uint opened this issue Sep 2, 2021 · 4 comments

Comments

@uint
Copy link

uint commented Sep 2, 2021

Most ways to construct values seem not to be usable in constants except for zero() and MAX. I wonder if it would be possible/desirable to have some way to construct these things in a const context, e.g. with from_big_endian()? Or by directly providing [u64; N_WORDS]?

Maybe then this could be made more convenient with macros, e.g. a macro that converts an integer literal to [u64; N_WORDS], usable in a const context.

@ordian
Copy link
Member

ordian commented Sep 2, 2021

It's possible to create it like

const THE_ANSWER: U256 = U256([42, 0, 0, 0]);

however, I agree a convenient method would be good.

@uint
Copy link
Author

uint commented Sep 2, 2021

It's possible to create it like

const THE_ANSWER: U256 = U256([42, 0, 0, 0]);

Ahh, I haven't noticed the field is public. Nice.

@webmaster128
Copy link
Contributor

In CosmWasm/cosmwasm#1071 you find a const implementation of from_be_bytes/from_le_bytes for inspiration. Getting something similar in uint directly would be 🎖

@vdods
Copy link

vdods commented Jul 29, 2023

FYI gakonst/ethers-rs#2486 (comment) -- uint v0.9.3 has a few functions that could be const that aren't (e.g. fn one), whereas uint v0.9.4 has them as const (not sure if it's maximally const).

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

No branches or pull requests

4 participants