本文主要是介绍Openzeppelin库第二期:Math库详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- SafeMath.sol: 安全运算
- Math.sol: uint256与uint64的最值获取
math.sol:
pragma solidity ^0.4.24;/*** @title Math* @dev Assorted math operations*/
library Math {// 取最大值function max64(uint64 _a, uint64 _b) internal pure returns (uint64) {return _a >= _b ? _a : _b;}// 取最小值function min64(uint64 _a, uint64 _b) internal pure returns (uint64) {return _a < _b ? _a : _b; // 三目运算符}function max256(uint256 _a, uint256 _b) internal pure returns (uint256) {return _a >= _b ? _a : _b;}function min256(uint256 _a, uint256 _b) internal pure returns (uint256) {return _a < _b ? _a : _b;}
}
SafeMath.sol:
pragma solidity ^0.4.24;/*** @title SafeMath* @dev Math operations with safety checks that throw on error*/// 安全
这篇关于Openzeppelin库第二期:Math库详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!