Skip to content

Commit

Permalink
big float features ln refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Jul 4, 2024
1 parent 5a6a5e8 commit b4e1882
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ multiversx_sc::imports!();
pub mod big_float_methods;
pub mod big_float_methods_wrapped;
pub mod big_float_operators;
pub mod big_float_operators_ln;
pub mod big_float_operators_wrapped;

#[multiversx_sc::contract]
pub trait BigFloatFeatures:
big_float_methods::BigFloatMethods
+ big_float_operators::BigFloatOperators
+ big_float_methods_wrapped::BigFloatWrappedMethods
+ big_float_operators_ln::BigFloatWrappedLn
+ big_float_operators_wrapped::BigFloatWrappedOperators
{
#[init]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,4 @@ pub trait BigFloatOperators {
r /= b;
r
}
#[endpoint]
fn ln_big_float_ref(&self, a: &BigFloat) -> BigFloat {
a.ln()
.unwrap_or_else(|| sc_panic!("log argument must pe strictly positive"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
multiversx_sc::imports!();

#[multiversx_sc::module]
pub trait BigFloatWrappedLn {
#[endpoint]
fn ln_big_float_ref(&self, a: &BigFloat) -> BigFloat {
a.ln()
.unwrap_or_else(|| sc_panic!("log argument must pe strictly positive"))
}

#[endpoint]
fn ln_big_float_ref_wrapped(
&self,
a: BigInt,
precision: usize,
) -> ManagedDecimalSigned<Self::Api, usize> {
let number = self.ln_big_float_ref(&BigFloat::from(a));
number.to_managed_decimal_signed(precision)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,4 @@ pub trait BigFloatWrappedOperators: big_float_operators::BigFloatOperators {
let number = self.div_assign_big_float_ref(&BigFloat::from(a), &BigFloat::from(b));
number.to_fixed_point(&BigFloat::from(fixed_point_denominator))
}

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

0 comments on commit b4e1882

Please sign in to comment.