Skip to content

Commit

Permalink
BigFloat - ln optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Jun 13, 2024
1 parent b86ac8e commit 0f0bff6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions framework/base/src/types/managed/basic/big_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,19 @@ impl<M: ManagedTypeApi> BigFloat<M> {
debug_assert!(x >= 1);
debug_assert!(x <= 2);

let mut result = BigFloat::from_frac(-56570851i64, 1_000_000_000i64); // -0.056570851, 9 decimals;
const DENOMINATOR: i64 = 1_000_000_000;

let mut result = BigFloat::from_frac(-56570851, DENOMINATOR); // -0.056570851
result *= &x;
result += BigFloat::from_frac(44717955i64, 100_000_000i64); // 0.44717955, 8 decimals;
result += BigFloat::from_frac(447179550, DENOMINATOR); // 0.44717955
result *= &x;
result += BigFloat::from_frac(-14699568i64, 10_000_000i64); // -1.4699568, 7 decimals;
result += BigFloat::from_frac(-1469956800, DENOMINATOR); // -1.4699568
result *= &x;
result += BigFloat::from_frac(28212026i64, 10_000_000i64); // 2.8212026, 7 decimals;
result += BigFloat::from_frac(2821202600, DENOMINATOR); // 2.8212026
result *= &x;
result += BigFloat::from_frac(-17417939i64, 10_000_000i64); // -1.7417939, 7 decimals;
result += BigFloat::from_frac(-1741793900, DENOMINATOR); // -1.7417939

let ln_of_2 = BigFloat::from_frac(69314718i64, 100_000_000i64); // 0.69314718 8 decimals
let ln_of_2 = BigFloat::from_frac(693147180, DENOMINATOR); // 0.69314718
result += BigFloat::from(bit_log2 as i32) * ln_of_2;

result
Expand Down

0 comments on commit 0f0bff6

Please sign in to comment.