> For the complete documentation index, see [llms.txt](https://docs.divergence-protocol.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.divergence-protocol.com/technical-reference/core/libraries/tickmath.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.divergence-protocol.com/technical-reference/core/libraries/tickmath.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
