Skip to main content
Helpful?

SafeCast

Git Source - Generated with forge doc

Contains methods for safely casting between types

Functions

toUint160

Cast a uint256 to a uint160, revert on overflow

function toUint160(uint256 x) internal pure returns (uint160 y);

Parameters

NameTypeDescription
xuint256The uint256 to be downcasted

Returns

NameTypeDescription
yuint160The downcasted integer, now type uint160

toUint128

Cast a uint256 to a uint128, revert on overflow

function toUint128(uint256 x) internal pure returns (uint128 y);

Parameters

NameTypeDescription
xuint256The uint256 to be downcasted

Returns

NameTypeDescription
yuint128The downcasted integer, now type uint128

toUint128

Cast a int128 to a uint128, revert on overflow or underflow

function toUint128(int128 x) internal pure returns (uint128 y);

Parameters

NameTypeDescription
xint128The int128 to be casted

Returns

NameTypeDescription
yuint128The casted integer, now type uint128

toInt128

Cast a int256 to a int128, revert on overflow or underflow

function toInt128(int256 x) internal pure returns (int128 y);

Parameters

NameTypeDescription
xint256The int256 to be downcasted

Returns

NameTypeDescription
yint128The downcasted integer, now type int128

toInt256

Cast a uint256 to a int256, revert on overflow

function toInt256(uint256 x) internal pure returns (int256 y);

Parameters

NameTypeDescription
xuint256The uint256 to be casted

Returns

NameTypeDescription
yint256The casted integer, now type int256

toInt128

Cast a uint256 to a int128, revert on overflow

function toInt128(uint256 x) internal pure returns (int128);

Parameters

NameTypeDescription
xuint256The uint256 to be downcasted

Returns

NameTypeDescription
<none>int128The downcasted integer, now type int128

Errors

SafeCastOverflow

error SafeCastOverflow();
Helpful?