Skip to content

Commit

Permalink
big float features ln test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Jul 4, 2024
1 parent b4e1882 commit fa61b20
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,32 @@
},
{
"step": "scCall",
"id": "LnBigFloatRef - 1",
"id": "ln_big_float_precision_9(23)",
"comment": "ln(23) = 3.135514648 (9 decimals)",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features",
"function": "ln_big_float_ref_wrapped",
"function": "ln_big_float_precision_9",
"arguments": [
"23"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [
"+3135514648"
]
}
},
{
"step": "scCall",
"id": "ln_big_float_any_precision(23, 9)",
"comment": "ln(23) = 3.135514648 (9 decimals)",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features",
"function": "ln_big_float_any_precision",
"arguments": [
"23",
"9"
Expand All @@ -31,7 +52,7 @@
},
"expect": {
"out": [
"0x0000000500bae4281800000009"
"u32:5|+3135514648|u32:9"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ pub trait BigFloatWrappedLn {
}

#[endpoint]
fn ln_big_float_ref_wrapped(
fn ln_big_float_precision_9(
&self,
a: BigInt,
) -> ManagedDecimalSigned<Self::Api, ConstDecimals<9>> {
let number = self.ln_big_float_ref(&BigFloat::from(a));
number.to_managed_decimal_signed(ConstDecimals)
}

#[endpoint]
fn ln_big_float_any_precision(
&self,
a: BigInt,
precision: usize,
Expand Down
9 changes: 5 additions & 4 deletions contracts/feature-tests/big-float-features/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 72
// Endpoints: 73
// Async Callback (empty): 1
// Total number of exported functions: 74
// Total number of exported functions: 75

#![no_std]

Expand Down Expand Up @@ -54,7 +54,6 @@ multiversx_sc_wasm_adapter::endpoints! {
mul_assign_big_float_ref => mul_assign_big_float_ref
div_assign_big_float => div_assign_big_float
div_assign_big_float_ref => div_assign_big_float_ref
ln_big_float_ref => ln_big_float_ref
new_from_parts_big_float_wrapped => new_from_parts_big_float_wrapped
new_from_frac_big_float_wrapped => new_from_frac_big_float_wrapped
new_from_sci_big_float_wrapped => new_from_sci_big_float_wrapped
Expand All @@ -73,6 +72,9 @@ multiversx_sc_wasm_adapter::endpoints! {
pow_big_float_ref_wrapped => pow_big_float_ref_wrapped
big_float_zero_wrapped => big_float_zero_wrapped
big_float_neg_wrapped => big_float_neg_wrapped
ln_big_float_ref => ln_big_float_ref
ln_big_float_precision_9 => ln_big_float_precision_9
ln_big_float_any_precision => ln_big_float_any_precision
add_big_float_wrapped => add_big_float_wrapped
add_big_float_ref_wrapped => add_big_float_ref_wrapped
sub_big_float_wrapped => sub_big_float_wrapped
Expand All @@ -89,7 +91,6 @@ multiversx_sc_wasm_adapter::endpoints! {
mul_assign_big_float_ref_wrapped => mul_assign_big_float_ref_wrapped
div_assign_big_float_wrapped => div_assign_big_float_wrapped
div_assign_big_float_ref_wrapped => div_assign_big_float_ref_wrapped
ln_big_float_ref_wrapped => ln_big_float_ref_wrapped
)
}

Expand Down

0 comments on commit fa61b20

Please sign in to comment.