> For the complete documentation index, see [llms.txt](https://docs.dragonswap.app/dragonswap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dragonswap.app/dragonswap/resources/developer-resources/smart-contracts/dragonswapv2/core/libraries/safecast.md).

# SafeCast

Contains methods for safely casting between types

### Functions[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#functions) <a href="#functions" id="functions"></a>

#### toUint160[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#touint160) <a href="#touint160" id="touint160"></a>

```solidity
  function toUint160(
    uint256 y
  ) internal pure returns (uint160 z)
```

Cast a uint256 to a uint160, revert on overflow

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#parameters)

| Name | Type    | Description                  |
| ---- | ------- | ---------------------------- |
| `y`  | uint256 | The uint256 to be downcasted |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#return-values)

| Name | Type    | Description                              |
| ---- | ------- | ---------------------------------------- |
| `z`  | uint160 | The downcasted integer, now type uint160 |

#### toInt128[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#toint128) <a href="#toint128" id="toint128"></a>

```solidity
  function toInt128(
    int256 y
  ) internal pure returns (int128 z)
```

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

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#parameters-1)

| Name | Type   | Description                 |
| ---- | ------ | --------------------------- |
| `y`  | int256 | The int256 to be downcasted |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#return-values-1)

| Name | Type   | Description                             |
| ---- | ------ | --------------------------------------- |
| `z`  | int128 | The downcasted integer, now type int128 |

#### toInt256[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#toint256) <a href="#toint256" id="toint256"></a>

```solidity
  function toInt256(
    uint256 y
  ) internal pure returns (int256 z)
```

Cast a uint256 to a int256, revert on overflow

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#parameters-2)

| Name | Type    | Description              |
| ---- | ------- | ------------------------ |
| `y`  | uint256 | The uint256 to be casted |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SafeCast#return-values-2)

| Name | Type   | Description                         |
| ---- | ------ | ----------------------------------- |
| `z`  | int256 | The casted integer, now type int256 |
