unshETH - Dependencies
Math-I.sol
Note
Split reference
This reference file was too long so it is split into multiple chunks. This is chunk number I.
This is a Solidity file that provides standard mathematical utility functions that are not available in the Solidity language. It includes functions for finding the maximum, minimum, average, and square root of numbers, as well as functions for performing division and multiplication with full precision. It also includes a function for calculating the logarithm to the base 2 of a number.
Math
A library that provides standard mathematical utility functions not available in the Solidity language.
Rounding
(Down
| Up
| Zero
): An enumeration that defines different rounding directions.
max
function max(uint256 a, uint256 b) internal pure returns (uint256)
Returns the largest of two numbers.
Parameters
- a uint256: The first number for comparison.
- b uint256: The second number for comparison.
Return Values
- uint256: The maximum of the two input numbers.
min
function min(uint256 a, uint256 b) internal pure returns (uint256)
Returns the smallest of two numbers.
Parameters
- a uint256: The first number for comparison.
- b uint256: The second number for comparison.
Return Values
- uint256: The minimum of the two input numbers.
average
function average(uint256 a, uint256 b) internal pure returns (uint256)
Returns the average of two numbers. The result is rounded towards zero.
Parameters
- a uint256: The first number for averaging.
- b uint256: The second number for averaging.
Return Values
- uint256: The average of the two input numbers, rounded towards zero.
ceilDiv
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256)
Returns the ceiling of the division of two numbers, rounding up instead of down.
Parameters
- a uint256: The dividend.
- b uint256: The divisor.
Return Values
- uint256: The result of the division, rounded up.
mulDiv
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result)
Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0.
Parameters
- x uint256: The first number for multiplication.
- y uint256: The second number for multiplication.
- denominator uint256: The denominator for division.
Return Values
- uint256: The result of the multiplication and division.
sqrt
function sqrt(uint256 a) internal pure returns (uint256)
Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
Parameters
- a uint256: The number to find the square root of.
Return Values
- uint256: The square root of the input number, rounded down.