Large u256 literals

I’m trying to define a large number in a Sway unit test, but getting the following issue:

280 |   let expected: u256 = 160149899619106589403934712464197979;
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ int literal out of range

How can I define large integers?

pub struct U256 {
    /// The most significant 64 bits of the `U256`.
    a: u64,
    /// The 65-128th most significant bits of the `U256`.
    b: u64,
    /// The 129-192nd most significant bits of the `U256`.
    c: u64,
    /// The 193-256th most significant bits of the `U256`.
    d: u64,

I don’t think it can just take the raw number, I believe you need to decompose your number into 4 64 bit pieces and then reconstruct it

I’m trying to use the native u256, not the U256 library.

I worded around it by converting to hex and using the 0x1234u256 notation. But would still be nice to have decimal literals as well.

Yes, @FossilFrank, that is the correct way to do it. I will bring this up with the team to discuss implementing decimal literals.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.