1

I'm finding a library to implement this formula in solidity.enter image description here

Is there is a library to implement this formula.

Haseeb Saeed
  • 683
  • 4
  • 22

1 Answers1

1

Use PRBMath!

// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

import "prb-math/contracts/PRBMathSD59x18.sol";

contract SignedConsumer { using PRBMathSD59x18 for int256;

/// @notice Calculates x*PIĆ·1e18 while handling possible intermediary overflow. function multiplyByPi(int256 x) external pure returns (int256 result) { int256 pi = PRBMathSD59x18.pi(); result = x.mul(pi); } }

P.S. see my comparison of fixed-point math libraries for Solidity: What fixed or float point math libraries are available in solidity?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143