Skip to content

I want to implement 4.pow(0.5) #50

Closed Answered by PaulRBerg
GalaxySciTech asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @lailaibtc! You can do that calculation like this:

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

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

contract UnsignedConsumer {
    using PRBMathUD60x18 for uint256;

    function foo() external returns (uint256 result) {
        const base = 4e18;
        const exp = 5e17;
        result = base.pow(exp);
    } 
}

You can try this on Remix. The result you get be should be 2000000000000000000, which is 2e18.

Make sure to read the NatSpec documentation for the pow function so that you understand how it works more precisely. Also check out this convertor tool that will help you convert between 18-decimals number (wads) and n…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@PaulRBerg
Comment options

@GalaxySciTech
Comment options

@PaulRBerg
Comment options

@GalaxySciTech
Comment options

@PaulRBerg
Comment options

Answer selected by GalaxySciTech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #50 on September 22, 2021 12:40.