Mc/ts increase error tolerance for binary search (#258)

* ts: a higher error tolerance is sufficient

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fixes from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* program: fix error size

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-09-30 14:59:12 +02:00 committed by GitHub
parent a2f4cef940
commit d1079bb1b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -1158,7 +1158,7 @@ fn binary_search(
fun: impl Fn(I80F48) -> I80F48,
) -> Result<I80F48> {
let max_iterations = 20;
let target_error = I80F48!(0.01);
let target_error = I80F48!(0.1);
require_msg!(
(left_value - target_value).signum() * (right_value - target_value).signum() != I80F48::ONE,
"internal error: left {} and right {} don't contain the target value {}",
@ -2096,7 +2096,7 @@ mod tests {
println!(
"checking for price_factor: {price_factor}, target ratio {ratio}: actual ratio: {actual_ratio}, plus ratio: {plus_ratio}, base_lots: {base_lots}",
);
let max_binary_search_error = 0.01;
let max_binary_search_error = 0.1;
assert!(ratio <= actual_ratio);
assert!(plus_ratio - max_binary_search_error <= ratio);
};

View File

@ -431,8 +431,7 @@ export class HealthCache {
healthRatioAfterActionFn: (I80F48) => I80F48,
): I80F48 {
const maxIterations = 40;
// TODO: make relative to health ratio decimals? Might be over engineering
const targetError = I80F48.fromNumber(0.001);
const targetError = I80F48.fromNumber(0.1);
if (
(leftRatio.sub(targetRatio).isPos() &&