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.

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.