Calculate Poweralgorithm

Source

CALCULATION POWER

Calculate Power using recursion

the logic of Power in the simple function.

short if explain

powerNum != 0 ? result = baseNum * power(baseNum, powerNum - 1) : result = 1;

normal solution

{ result = baseNum ** powerNum; }

  • mathematical symbol ^ , in solidity **

Review

  • SmartContract
function power(uint baseNum, uint powerNum) internal pure returns (uint result) {
    powerNum != 0 ? result = baseNum * power(baseNum, powerNum - 1) : result = 1;
}