LibMath
Author: Felipe Argento
Functions
ctz
Count trailing zeros.
This is a binary search implementation.
function ctz(uint256 x) internal pure returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
x | uint256 | The number you want the ctz of |
clz
Count leading zeros.
This a binary search implementation.
function clz(uint256 x) internal pure returns (uint256 n);
Parameters
| Name | Type | Description |
|---|---|---|
x | uint256 | The number you want the clz of |
Returns
| Name | Type | Description |
|---|---|---|
n | uint256 | The number of leading zeros in x |
ceilLog2
The smallest y for which x <= 2^y.
This is a binary search implementation.
function ceilLog2(uint256 x) internal pure returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
x | uint256 | The number you want the ceilLog2 of |
floorLog2
The biggest y for which x >= 2^y.
This is a binary search implementation.
This function reverts if x = 0 is provided.
function floorLog2(uint256 x) internal pure returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
x | uint256 | The number you want the floorLog2 of |
max
The largest of two numbers.
function max(uint256 x, uint256 y) internal pure returns (uint256);
min
The smallest of two numbers.
function min(uint256 x, uint256 y) internal pure returns (uint256);
Errors
FloorLog2OfZeroIsUndefined
Tried to compute floorLog2(0), which is undefined.
error FloorLog2OfZeroIsUndefined();