# TickMath

As digital calls and puts are priced between \[0.01, 0.99] per collateral, per put-call parity, the sqrtPrice is the sqrt ratio of shieldPrice/spearPrice is between \[sqrt(1/99), sqrt(99)].  sqrtPrice is computed for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers.

## getSqrtRatioAtTick

Calculates and returns the square root ratio at the given tick.

```javascript
function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96)
```

**Params:**

| **Name** | **Type** | **Description**                      |
| -------- | -------- | ------------------------------------ |
| tick     | int24    | The input tick for the above formula |

**Returns:**

| **Name**     | **Type** | **Description**                                                                          |
| ------------ | -------- | ---------------------------------------------------------------------------------------- |
| sqrtPriceX96 | uint160  | A fixed point Q64.96 number representing the sqrt of the ratio of shieldPrice/spearPrice |

## getTickAtSqrtRatio

Calculates and returns the tick value at the given square root ratio.

```javascript
function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick)
```

**Params:**

| **Name**     | **Type** | **Description**                                          |
| ------------ | -------- | -------------------------------------------------------- |
| sqrtPriceX96 | uint160  | The sqrt ratio for which to compute the tick as a Q64.96 |

**Returns:**

| **Name** | **Type** | **Description**                                                                |
| -------- | -------- | ------------------------------------------------------------------------------ |
| tick     | int24    | The greatest tick for which the price is less than or equal to the input ratio |


---

# 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://docs.divergence-protocol.com/technical-reference/core/libraries/tickmath.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.
