-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: perform more precise
sqrt
on bignumbers in FluidDex
- Loading branch information
1 parent
28ad697
commit 631cd72
Showing
2 changed files
with
22 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { BigNumber } from 'ethers'; | ||
|
||
const ONE = BigNumber.from(1); | ||
const TWO = BigNumber.from(2); | ||
|
||
export function sqrt(value: BigNumber) { | ||
let x = value; | ||
let z = x.add(ONE).div(TWO); | ||
let y = x; | ||
while (z.sub(y).isNegative()) { | ||
y = z; | ||
z = x.div(z).add(z).div(TWO); | ||
} | ||
return y; | ||
} |