Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

LibMath

Git Source

Author: Felipe Argento

Functions

ctz

Count trailing zeros.

This is a binary search implementation.

function ctz(uint256 x) internal pure returns (uint256);

Parameters

NameTypeDescription
xuint256The 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

NameTypeDescription
xuint256The number you want the clz of

Returns

NameTypeDescription
nuint256The 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

NameTypeDescription
xuint256The 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

NameTypeDescription
xuint256The 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();