SignedMath
Performs signed math operations safely, reverting with a custom error in case of overflow.
Functions
safeAdd
Safely adds two signed integers, reverting on overflow.
function safeAdd(int256 lhs, int256 rhs) internal pure returns (int256 res_);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |
rhs | int256 | The right-hand side operand. |
Returns
| Name | Type | Description |
|---|---|---|
res_ | int256 | The result of lhs + rhs. |
safeSub
Safely subtracts two signed integers, reverting on overflow.
function safeSub(int256 lhs, int256 rhs) internal pure returns (int256 res_);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |
rhs | int256 | The right-hand side operand. |
Returns
| Name | Type | Description |
|---|---|---|
res_ | int256 | The result of lhs - rhs. |
safeMul
Safely multiplies two signed integers, reverting on overflow.
function safeMul(int256 lhs, int256 rhs) internal pure returns (int256 res_);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |
rhs | int256 | The right-hand side operand. |
Returns
| Name | Type | Description |
|---|---|---|
res_ | int256 | The result of lhs * rhs. |
safeDiv
Safely divides two signed integers, reverting on division by zero.
function safeDiv(int256 lhs, int256 rhs) internal pure returns (int256 res_);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |
rhs | int256 | The right-hand side operand. |
Returns
| Name | Type | Description |
|---|---|---|
res_ | int256 | The result of lhs / rhs. |
Errors
SignedMathOverflowedAdd
The signed add operation overflowed.
error SignedMathOverflowedAdd(int256 lhs, int256 rhs);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |
rhs | int256 | The right-hand side operand. |
SignedMathOverflowedSub
The signed sub operation overflowed.
error SignedMathOverflowedSub(int256 lhs, int256 rhs);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |
rhs | int256 | The right-hand side operand. |
SignedMathOverflowedMul
The signed mul operation overflowed.
error SignedMathOverflowedMul(int256 lhs, int256 rhs);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |
rhs | int256 | The right-hand side operand. |
SignedMathOverflowedDiv
The signed div operation overflowed.
error SignedMathOverflowedDiv(int256 lhs, int256 rhs);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |
rhs | int256 | The right-hand side operand. |
SignedMathDivideByZero
A division by zero occurred.
error SignedMathDivideByZero(int256 lhs);
Parameters
| Name | Type | Description |
|---|---|---|
lhs | int256 | The left-hand side operand. |