Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions math/fixed_point/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ Fixed-point decimal types with 9 decimals (10^9), matching Sui coin precision.
## Casting and helpers

```rust
use openzeppelin_fp_math::{casting_u128, sd29x9, ud30x9};
use openzeppelin_fp_math::{sd29x9, ud30x9};
use openzeppelin_fp_math::casting_u128::into_UD30x9;
use fun into_UD30x9 as u128.into_UD30x9;

let value = ud30x9::wrap(1000000000); // 1.0
let value = casting_u128::into_UD30x9(1000000000);
let value = 1000000000_u128.into_UD30x9(); // Casting

let positive = sd29x9::wrap(1000000000, false); // 1.0
let negative = sd29x9::wrap(1000000000, true); // -1.0
Expand Down
6 changes: 4 additions & 2 deletions math/fixed_point/tests/ud30x9_tests.move
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#[test_only]
module openzeppelin_fp_math::ud30x9_tests;

use openzeppelin_fp_math::casting_u128;
use openzeppelin_fp_math::casting_u128::into_UD30x9;
use openzeppelin_fp_math::ud30x9::{Self, UD30x9};
use std::unit_test::assert_eq;

use fun into_UD30x9 as u128.into_UD30x9;

const MAX_VALUE: u128 = 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF;

// ==== Helpers ====
Expand Down Expand Up @@ -160,7 +162,7 @@ fun modulo_and_zero_helpers_match_u128() {
#[test]
fun casting_from_u128_matches_wrap() {
let raw = 987_654_321u128;
let casted = casting_u128::into_UD30x9(raw);
let casted = raw.into_UD30x9();
assert_eq!(casted.unwrap(), raw);

let manual = fixed(raw);
Expand Down
Loading