-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1022 from PhilippeR26/u512
feat: handling of cairo u512 type
- Loading branch information
Showing
17 changed files
with
3,567 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Cairo 2.6.0 | ||
|
||
use core::integer::u512; | ||
|
||
#[starknet::interface] | ||
trait IUint512<TContractState> { | ||
fn get_u512(self: @TContractState) -> u512; | ||
fn return_u512(self: @TContractState, my_u512: u512) -> u512; | ||
fn div_u512(self: @TContractState, my_u512: u512, divisor: u256) -> (u512, u256); | ||
} | ||
|
||
|
||
#[starknet::contract] | ||
mod TestUint512 { | ||
use core::integer::{u512, u512_safe_div_rem_by_u256}; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[abi(embed_v0)] | ||
impl Uint512 of super::IUint512<ContractState> { | ||
fn get_u512(self: @ContractState) -> u512 { | ||
u512 { | ||
limb0: 0x00000000000000000000000000000000, | ||
limb1: 0x11111111111111111111111111111111, | ||
limb2: 0x22222222222222222222222222222222, | ||
limb3: 0x33333333333333333333333333333333, | ||
} | ||
} | ||
|
||
fn return_u512(self: @ContractState, my_u512: u512) -> u512 { | ||
my_u512 | ||
} | ||
|
||
fn div_u512(self: @ContractState, my_u512: u512, divisor: u256) -> (u512, u256) { | ||
let (q, r) = u512_safe_div_rem_by_u256(my_u512, divisor.try_into().unwrap()); | ||
(q, r) | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.