Skip to content

Commit ceb5b60

Browse files
authored
Merge pull request #217 from Aursen/u256
2 parents ea2201f + 716d0fd commit ceb5b60

File tree

1 file changed

+18
-0
lines changed
  • packages/injective-math/src/fp_decimal

1 file changed

+18
-0
lines changed

packages/injective-math/src/fp_decimal/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ impl From<Uint128> for FPDecimal {
7272
}
7373
}
7474

75+
impl From<FPDecimal> for Uint256 {
76+
fn from(value: FPDecimal) -> Self {
77+
value.to_u256()
78+
}
79+
}
80+
7581
impl From<Uint256> for FPDecimal {
7682
fn from(x: Uint256) -> FPDecimal {
7783
FPDecimal::from_str(&x.to_string()).unwrap()
@@ -456,6 +462,18 @@ mod tests {
456462
assert_eq!(uint256, Uint256::from(12345u64));
457463
}
458464

465+
#[test]
466+
fn test_into_u256() {
467+
let fp_decimal: Uint256 = FPDecimal {
468+
num: U256::from(12345u64),
469+
sign: 1, // Assuming it's always positive
470+
}
471+
.into();
472+
let u256 = Uint256::from(12345u64);
473+
474+
assert_eq!(u256, fp_decimal)
475+
}
476+
459477
#[test]
460478
fn into_uint256_floor() {
461479
let fp_decimal = FPDecimal {

0 commit comments

Comments
 (0)