# LowGasSafeMath

Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost

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

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

```solidity
  function add(
    uint256 x,
    uint256 y
  ) internal pure returns (uint256 z)
```

Returns x + y, reverts if sum overflows uint256

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

| Name | Type    | Description |
| ---- | ------- | ----------- |
| `x`  | uint256 | The augend  |
| `y`  | uint256 | The addend  |

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

| Name | Type    | Description        |
| ---- | ------- | ------------------ |
| `z`  | uint256 | The sum of x and y |

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

```solidity
  function sub(
    uint256 x,
    uint256 y
  ) internal pure returns (uint256 z)
```

Returns x - y, reverts if underflows

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

| Name | Type    | Description    |
| ---- | ------- | -------------- |
| `x`  | uint256 | The minuend    |
| `y`  | uint256 | The subtrahend |

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

| Name | Type    | Description               |
| ---- | ------- | ------------------------- |
| `z`  | uint256 | The difference of x and y |

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

```solidity
  function mul(
    uint256 x,
    uint256 y
  ) internal pure returns (uint256 z)
```

Returns x \* y, reverts if overflows

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

| Name | Type    | Description      |
| ---- | ------- | ---------------- |
| `x`  | uint256 | The multiplicand |
| `y`  | uint256 | The multiplier   |

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

| Name | Type    | Description            |
| ---- | ------- | ---------------------- |
| `z`  | uint256 | The product of x and y |

#### add[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/LowGasSafeMath#add-1) <a href="#add-1" id="add-1"></a>

```solidity
  function add(
    int256 x,
    int256 y
  ) internal pure returns (int256 z)
```

Returns x + y, reverts if overflows or underflows

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

| Name | Type   | Description |
| ---- | ------ | ----------- |
| `x`  | int256 | The augend  |
| `y`  | int256 | The addend  |

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

| Name | Type   | Description        |
| ---- | ------ | ------------------ |
| `z`  | int256 | The sum of x and y |

#### sub[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/LowGasSafeMath#sub-1) <a href="#sub-1" id="sub-1"></a>

```solidity
  function sub(
    int256 x,
    int256 y
  ) internal pure returns (int256 z)
```

Returns x - y, reverts if overflows or underflows

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

| Name | Type   | Description    |
| ---- | ------ | -------------- |
| `x`  | int256 | The minuend    |
| `y`  | int256 | The subtrahend |

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

| Name | Type   | Description               |
| ---- | ------ | ------------------------- |
| `z`  | int256 | The difference of x and y |
