Skip to content

Commit

Permalink
Merge branch 'dev' into f/add-derivative-orderbook-query
Browse files Browse the repository at this point in the history
  • Loading branch information
gorgos authored Nov 7, 2023
2 parents 9eddc61 + 6293909 commit 718dceb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 180 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/injective-math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
name = "injective-math"
readme = "README.md"
repository = "https://github.com/InjectiveLabs/cw-injective/tree/master/packages/injective-math"
version = "0.2.0"
version = "0.2.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
219 changes: 43 additions & 176 deletions packages/injective-math/src/fp_decimal/exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,93 +102,50 @@ impl FPDecimal {
return Some(FPDecimal::from(32768u128));
}

if FPDecimal::ONE.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE);
}
if FPDecimal::TWO.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::TWO);
}
if FPDecimal::THREE.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::THREE);
}
if FPDecimal::FOUR.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::FOUR);
}
if FPDecimal::FIVE.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::FIVE);
}
if FPDecimal::SIX.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::SIX);
}
if FPDecimal::SEVEN.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::SEVEN);
}
if FPDecimal::EIGHT.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::EIGHT);
}
if FPDecimal::NINE.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::NINE);
}
if FPDecimal::TEN.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::TEN);
}
if FPDecimal::ELEVEN.log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ELEVEN);
}
if FPDecimal::from(12u128).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::from(12u128));
}
if FPDecimal::from(13u128).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::from(13u128));
}
if FPDecimal::from(14u128).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::from(14u128));
}
if FPDecimal::from(15u128).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::from(15u128));
}

if (FPDecimal::ONE / FPDecimal::TWO).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::TWO);
}
if (FPDecimal::ONE / FPDecimal::THREE).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::THREE);
}
if (FPDecimal::ONE / FPDecimal::FOUR).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::FOUR);
}
if (FPDecimal::ONE / FPDecimal::FIVE).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::FIVE);
}
if (FPDecimal::ONE / FPDecimal::SIX).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::SIX);
}
if (FPDecimal::ONE / FPDecimal::SEVEN).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::SEVEN);
}
if (FPDecimal::ONE / FPDecimal::EIGHT).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::EIGHT);
}
if (FPDecimal::ONE / FPDecimal::NINE).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::NINE);
}
if (FPDecimal::ONE / FPDecimal::TEN).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::TEN);
}
if (FPDecimal::ONE / FPDecimal::ELEVEN).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::ELEVEN);
}
if (FPDecimal::ONE / FPDecimal::from(12u128)).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::from(12u128));
}
if (FPDecimal::ONE / FPDecimal::from(13u128)).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::from(13u128));
}
if (FPDecimal::ONE / FPDecimal::from(14u128)).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::from(14u128));
fn check_log_2(x: &FPDecimal, exponent: &FPDecimal) -> bool {
match x.log2() {
Some(v) => v == *exponent,
None => false,
}
}
if (FPDecimal::ONE / FPDecimal::from(15u128)).log2().is_some_and(|x| x == exponent) {
return Some(FPDecimal::ONE / FPDecimal::from(15u128));
let special_checks = [
FPDecimal::ONE,
FPDecimal::TWO,
FPDecimal::THREE,
FPDecimal::FOUR,
FPDecimal::FIVE,
FPDecimal::SIX,
FPDecimal::SEVEN,
FPDecimal::EIGHT,
FPDecimal::NINE,
FPDecimal::TEN,
FPDecimal::ELEVEN,
FPDecimal::from(12u128),
FPDecimal::from(13u128),
FPDecimal::from(14u128),
FPDecimal::from(15u128),
FPDecimal::ONE / FPDecimal::TWO,
FPDecimal::ONE / FPDecimal::THREE,
FPDecimal::ONE / FPDecimal::FOUR,
FPDecimal::ONE / FPDecimal::FIVE,
FPDecimal::ONE / FPDecimal::SIX,
FPDecimal::ONE / FPDecimal::SEVEN,
FPDecimal::ONE / FPDecimal::EIGHT,
FPDecimal::ONE / FPDecimal::NINE,
FPDecimal::ONE / FPDecimal::TEN,
FPDecimal::ONE / FPDecimal::ELEVEN,
FPDecimal::ONE / FPDecimal::from(12u128),
FPDecimal::ONE / FPDecimal::from(13u128),
FPDecimal::ONE / FPDecimal::from(14u128),
FPDecimal::ONE / FPDecimal::from(15u128),
];
for x in special_checks.iter() {
if check_log_2(x, &exponent) {
return Some(*x);
}
if check_log_2(x, &(-exponent)) {
return Some(FPDecimal::ONE / *x);
}
}

if exponent == -FPDecimal::TWO {
Expand Down Expand Up @@ -233,96 +190,6 @@ impl FPDecimal {
if exponent == -FPDecimal::from(15u128) {
return Some(FPDecimal::ONE / FPDecimal::from(32768u128));
}

if FPDecimal::ONE.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE);
}
if FPDecimal::TWO.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::TWO);
}
if FPDecimal::THREE.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::THREE);
}
if FPDecimal::FOUR.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::FOUR);
}
if FPDecimal::FIVE.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::FIVE);
}
if FPDecimal::SIX.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::SIX);
}
if FPDecimal::SEVEN.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::SEVEN);
}
if FPDecimal::EIGHT.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::EIGHT);
}
if FPDecimal::NINE.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::NINE);
}
if FPDecimal::TEN.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::TEN);
}
if FPDecimal::ELEVEN.log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::ELEVEN);
}
if FPDecimal::from(12u128).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::from(12u128));
}
if FPDecimal::from(13u128).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::from(13u128));
}
if FPDecimal::from(14u128).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::from(14u128));
}
if FPDecimal::from(15u128).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ONE / FPDecimal::from(15u128));
}

if (FPDecimal::ONE / FPDecimal::TWO).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::TWO);
}
if (FPDecimal::ONE / FPDecimal::THREE).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::THREE);
}
if (FPDecimal::ONE / FPDecimal::FOUR).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::FOUR);
}
if (FPDecimal::ONE / FPDecimal::FIVE).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::FIVE);
}
if (FPDecimal::ONE / FPDecimal::SIX).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::SIX);
}
if (FPDecimal::ONE / FPDecimal::SEVEN).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::SEVEN);
}
if (FPDecimal::ONE / FPDecimal::EIGHT).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::EIGHT);
}
if (FPDecimal::ONE / FPDecimal::NINE).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::NINE);
}
if (FPDecimal::ONE / FPDecimal::TEN).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::TEN);
}
if (FPDecimal::ONE / FPDecimal::ELEVEN).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::ELEVEN);
}
if (FPDecimal::ONE / FPDecimal::from(12u128)).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::from(12u128));
}
if (FPDecimal::ONE / FPDecimal::from(13u128)).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::from(13u128));
}
if (FPDecimal::ONE / FPDecimal::from(14u128)).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::from(14u128));
}
if (FPDecimal::ONE / FPDecimal::from(15u128)).log2().is_some_and(|x| x == -exponent) {
return Some(FPDecimal::from(15u128));
}

None
}

Expand Down

0 comments on commit 718dceb

Please sign in to comment.