# Welcome

DeFiMath is a high-performance, open-source Solidity library designed for Ethereum smart contracts. It provides optimized, gas-efficient implementations of core DeFi primitives and mathematical utilities—built with precision and performance in mind.

### Why DefiMath?

* **DeFi primitives**: core building blocks tailored for advanced financial protocols like options, futures, and other derivatives.
* **Gas optimized**: carefully engineered for minimal gas usage without compromising precision.
* **High-precision math**: accurate fixed-point and integer operations essential for financial calculations.

### Get Started

Check out our [GitHub Repository](https://github.com/MerkleBlue/defimath) to explore the code and contribute.

### Stay Updated

Join our mailing list to receive the latest Solidity optimization tips and tricks, directly to your inbox.

Sign Up for Updates

### What's inside?

DeFiMath implements advanced math and derivatives functions in Solidity. The following tables provide overview of derivatives and math functions you can use:

<table><thead><tr><th width="93.18359375">Function</th><th width="379.453125">Description</th><th>Gas</th><th>Avg relative error</th></tr></thead><tbody><tr><td>call</td><td>European call option pricing</td><td>3203</td><td>5.6e-12</td></tr><tr><td>put</td><td>European put option pricing</td><td>3229</td><td>5.4e-12</td></tr><tr><td>delta</td><td>Call and put option price sensitivity to underlying change</td><td>2033</td><td>6.9e-15</td></tr><tr><td>gamma</td><td>Option price sensitivity to delta change</td><td>1707</td><td>9.1e-17</td></tr><tr><td>theta</td><td>Option price sensitivity to time change</td><td>3823</td><td>3.7e-14</td></tr><tr><td>vega</td><td>Call and put option price sensitivity to volatility change</td><td>1680</td><td>4.8e-14</td></tr><tr><td></td><td></td><td></td><td></td></tr></tbody></table>

<table><thead><tr><th width="93.44921875">Function</th><th width="379.453125">Description</th><th>Gas</th><th>Avg relative error</th></tr></thead><tbody><tr><td>exp</td><td>Exponential function</td><td>359</td><td>5.1e-12</td></tr><tr><td>ln</td><td>Natural logarithm</td><td>608</td><td>1.5e-12</td></tr><tr><td>log2</td><td>Logarithm with base 2</td><td>681</td><td>1.5e-12</td></tr><tr><td>log10</td><td>Logarithm with base 10</td><td>681</td><td>1.4e-12</td></tr><tr><td>sqrt</td><td>Square root function</td><td>383</td><td>2.8e-14</td></tr><tr><td>cdf</td><td>Standard normal cumulative distribution function</td><td>799</td><td>4.6e-13</td></tr><tr><td>erf</td><td>Error function</td><td>773</td><td>7.4e-13</td></tr></tbody></table>


---

# 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.defimath.com/welcome.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.
