049 MyMathLibrary

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

// A library for basic arithmetic operations.

library MyMathLibrary {

    // Sum two uint256 numbers.

    // @param a The first uint256 number.

    // @param b The second uint256 number.

    // @return The sum of `a` and `b`.

    function sum(uint256 a, uint256 b) public pure returns (uint256) {

        return a + b;

    }

    // Calculates the exponential (power) of a base `a` to an exponent `b`.

    // @param a The base uint256 number.

    // @param b The exponent uint256 number.

    // @return The result of `a` raised to the power of `b`.

    function exponential(uint256 a, uint256 b) public pure returns (uint256) {

        return a ** b;

    }

}

// A contract that includes basic arithmetic operations.

contract MyMathContract {

    // Sums two uint256 numbers.

    // This function directly utilizes Solidity's arithmetic operation to sum two numbers.

    // @param a The first uint256 number to be summed.

    // @param b The second uint256 number to be summed.

    // @return The sum of `a` and `b`.

    function sum(uint256 a, uint256 b) public pure returns (uint256) {

        return a + b;

    }

}

049 MyMathLibrary_第1张图片

你可能感兴趣的:(Solidity,区块链,智能合约,信任链,分布式账本,金融)