# SafeCast

[Git Source](https://github.com/traderjoe-xyz/joe-v2/blob/16f011d25e6bf6d0a0c479974345b623d491104f/src/libraries/math/SafeCast.sol)

**Author:**\
Trader Joe

This library contains functions to safely cast uint256 to different uint types.

## Functions

### safe248

*Returns x on uint248 and check that it does not overflow*

```solidity
function safe248(uint256 x) internal pure returns (uint248 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint248` | The value as an uint248 |

### safe240

*Returns x on uint240 and check that it does not overflow*

```solidity
function safe240(uint256 x) internal pure returns (uint240 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint240` | The value as an uint240 |

### safe232

*Returns x on uint232 and check that it does not overflow*

```solidity
function safe232(uint256 x) internal pure returns (uint232 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint232` | The value as an uint232 |

### safe224

*Returns x on uint224 and check that it does not overflow*

```solidity
function safe224(uint256 x) internal pure returns (uint224 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint224` | The value as an uint224 |

### safe216

*Returns x on uint216 and check that it does not overflow*

```solidity
function safe216(uint256 x) internal pure returns (uint216 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint216` | The value as an uint216 |

### safe208

*Returns x on uint208 and check that it does not overflow*

```solidity
function safe208(uint256 x) internal pure returns (uint208 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint208` | The value as an uint208 |

### safe200

*Returns x on uint200 and check that it does not overflow*

```solidity
function safe200(uint256 x) internal pure returns (uint200 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint200` | The value as an uint200 |

### safe192

*Returns x on uint192 and check that it does not overflow*

```solidity
function safe192(uint256 x) internal pure returns (uint192 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint192` | The value as an uint192 |

### safe184

*Returns x on uint184 and check that it does not overflow*

```solidity
function safe184(uint256 x) internal pure returns (uint184 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint184` | The value as an uint184 |

### safe176

*Returns x on uint176 and check that it does not overflow*

```solidity
function safe176(uint256 x) internal pure returns (uint176 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint176` | The value as an uint176 |

### safe168

*Returns x on uint168 and check that it does not overflow*

```solidity
function safe168(uint256 x) internal pure returns (uint168 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint168` | The value as an uint168 |

### safe160

*Returns x on uint160 and check that it does not overflow*

```solidity
function safe160(uint256 x) internal pure returns (uint160 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint160` | The value as an uint160 |

### safe152

*Returns x on uint152 and check that it does not overflow*

```solidity
function safe152(uint256 x) internal pure returns (uint152 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint152` | The value as an uint152 |

### safe144

*Returns x on uint144 and check that it does not overflow*

```solidity
function safe144(uint256 x) internal pure returns (uint144 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint144` | The value as an uint144 |

### safe136

*Returns x on uint136 and check that it does not overflow*

```solidity
function safe136(uint256 x) internal pure returns (uint136 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint136` | The value as an uint136 |

### safe128

*Returns x on uint128 and check that it does not overflow*

```solidity
function safe128(uint256 x) internal pure returns (uint128 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint128` | The value as an uint128 |

### safe120

*Returns x on uint120 and check that it does not overflow*

```solidity
function safe120(uint256 x) internal pure returns (uint120 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint120` | The value as an uint120 |

### safe112

*Returns x on uint112 and check that it does not overflow*

```solidity
function safe112(uint256 x) internal pure returns (uint112 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint112` | The value as an uint112 |

### safe104

*Returns x on uint104 and check that it does not overflow*

```solidity
function safe104(uint256 x) internal pure returns (uint104 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `y`  | `uint104` | The value as an uint104 |

### safe96

*Returns x on uint96 and check that it does not overflow*

```solidity
function safe96(uint256 x) internal pure returns (uint96 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint96` | The value as an uint96 |

### safe88

*Returns x on uint88 and check that it does not overflow*

```solidity
function safe88(uint256 x) internal pure returns (uint88 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint88` | The value as an uint88 |

### safe80

*Returns x on uint80 and check that it does not overflow*

```solidity
function safe80(uint256 x) internal pure returns (uint80 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint80` | The value as an uint80 |

### safe72

*Returns x on uint72 and check that it does not overflow*

```solidity
function safe72(uint256 x) internal pure returns (uint72 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint72` | The value as an uint72 |

### safe64

*Returns x on uint64 and check that it does not overflow*

```solidity
function safe64(uint256 x) internal pure returns (uint64 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint64` | The value as an uint64 |

### safe56

*Returns x on uint56 and check that it does not overflow*

```solidity
function safe56(uint256 x) internal pure returns (uint56 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint56` | The value as an uint56 |

### safe48

*Returns x on uint48 and check that it does not overflow*

```solidity
function safe48(uint256 x) internal pure returns (uint48 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint48` | The value as an uint48 |

### safe40

*Returns x on uint40 and check that it does not overflow*

```solidity
function safe40(uint256 x) internal pure returns (uint40 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint40` | The value as an uint40 |

### safe32

*Returns x on uint32 and check that it does not overflow*

```solidity
function safe32(uint256 x) internal pure returns (uint32 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint32` | The value as an uint32 |

### safe24

*Returns x on uint24 and check that it does not overflow*

```solidity
function safe24(uint256 x) internal pure returns (uint24 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint24` | The value as an uint24 |

### safe16

*Returns x on uint16 and check that it does not overflow*

```solidity
function safe16(uint256 x) internal pure returns (uint16 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type     | Description            |
| ---- | -------- | ---------------------- |
| `y`  | `uint16` | The value as an uint16 |

### safe8

*Returns x on uint8 and check that it does not overflow*

```solidity
function safe8(uint256 x) internal pure returns (uint8 y);
```

**Parameters**

| Name | Type      | Description             |
| ---- | --------- | ----------------------- |
| `x`  | `uint256` | The value as an uint256 |

**Returns**

| Name | Type    | Description           |
| ---- | ------- | --------------------- |
| `y`  | `uint8` | The value as an uint8 |

## Errors

### SafeCast\_\_Exceeds248Bits

```solidity
error SafeCast__Exceeds248Bits();
```

### SafeCast\_\_Exceeds240Bits

```solidity
error SafeCast__Exceeds240Bits();
```

### SafeCast\_\_Exceeds232Bits

```solidity
error SafeCast__Exceeds232Bits();
```

### SafeCast\_\_Exceeds224Bits

```solidity
error SafeCast__Exceeds224Bits();
```

### SafeCast\_\_Exceeds216Bits

```solidity
error SafeCast__Exceeds216Bits();
```

### SafeCast\_\_Exceeds208Bits

```solidity
error SafeCast__Exceeds208Bits();
```

### SafeCast\_\_Exceeds200Bits

```solidity
error SafeCast__Exceeds200Bits();
```

### SafeCast\_\_Exceeds192Bits

```solidity
error SafeCast__Exceeds192Bits();
```

### SafeCast\_\_Exceeds184Bits

```solidity
error SafeCast__Exceeds184Bits();
```

### SafeCast\_\_Exceeds176Bits

```solidity
error SafeCast__Exceeds176Bits();
```

### SafeCast\_\_Exceeds168Bits

```solidity
error SafeCast__Exceeds168Bits();
```

### SafeCast\_\_Exceeds160Bits

```solidity
error SafeCast__Exceeds160Bits();
```

### SafeCast\_\_Exceeds152Bits

```solidity
error SafeCast__Exceeds152Bits();
```

### SafeCast\_\_Exceeds144Bits

```solidity
error SafeCast__Exceeds144Bits();
```

### SafeCast\_\_Exceeds136Bits

```solidity
error SafeCast__Exceeds136Bits();
```

### SafeCast\_\_Exceeds128Bits

```solidity
error SafeCast__Exceeds128Bits();
```

### SafeCast\_\_Exceeds120Bits

```solidity
error SafeCast__Exceeds120Bits();
```

### SafeCast\_\_Exceeds112Bits

```solidity
error SafeCast__Exceeds112Bits();
```

### SafeCast\_\_Exceeds104Bits

```solidity
error SafeCast__Exceeds104Bits();
```

### SafeCast\_\_Exceeds96Bits

```solidity
error SafeCast__Exceeds96Bits();
```

### SafeCast\_\_Exceeds88Bits

```solidity
error SafeCast__Exceeds88Bits();
```

### SafeCast\_\_Exceeds80Bits

```solidity
error SafeCast__Exceeds80Bits();
```

### SafeCast\_\_Exceeds72Bits

```solidity
error SafeCast__Exceeds72Bits();
```

### SafeCast\_\_Exceeds64Bits

```solidity
error SafeCast__Exceeds64Bits();
```

### SafeCast\_\_Exceeds56Bits

```solidity
error SafeCast__Exceeds56Bits();
```

### SafeCast\_\_Exceeds48Bits

```solidity
error SafeCast__Exceeds48Bits();
```

### SafeCast\_\_Exceeds40Bits

```solidity
error SafeCast__Exceeds40Bits();
```

### SafeCast\_\_Exceeds32Bits

```solidity
error SafeCast__Exceeds32Bits();
```

### SafeCast\_\_Exceeds24Bits

```solidity
error SafeCast__Exceeds24Bits();
```

### SafeCast\_\_Exceeds16Bits

```solidity
error SafeCast__Exceeds16Bits();
```

### SafeCast\_\_Exceeds8Bits

```solidity
error SafeCast__Exceeds8Bits();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.lfj.gg/contracts/libraries/math/safecast.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
