From feb276ccfaab05458f96cfd24b7accf5135c0443 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Tue, 5 Apr 2022 15:16:51 -0500 Subject: [PATCH] Defensive break in binary search --- common/calculate-cpmm.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/calculate-cpmm.ts b/common/calculate-cpmm.ts index baadb31f..ab6fd3c5 100644 --- a/common/calculate-cpmm.ts +++ b/common/calculate-cpmm.ts @@ -151,6 +151,8 @@ function calculateCpmmShareValue( let kGuess = 0 while (Math.abs(k - kGuess) > 0.00000000001) { mid = lowAmount + (highAmount - lowAmount) / 2 + if (mid === lowAmount || mid === highAmount) break + kGuess = sellSharesK(pool.YES, pool.NO, p, shares, outcome, mid) if (kGuess < k) { highAmount = mid