> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/tanh.md).

# tanh

Use the `tanh()` function to calculate the hyperbolic tangent of a numeric value.

## Syntax

```sql
tanh(<number>)
```

## Parameters

| Name     | Type           | Required | Description                                                                                |
| -------- | -------------- | -------- | ------------------------------------------------------------------------------------------ |
| `number` | integer, float | Yes      | The numeric value for which to calculate the hyperbolic tangent. Any real number is valid. |

## Returns

**Type**: float

**Description**: The `tanh()` function returns the hyperbolic tangent of the input value. The resulting value is within the range (-1, 1). If the input is `null`, the function returns `null`.

## Usage notes

* **Input type**: XQL doesn't support NaN or infinite values as input and these value types also can not be returned.
* **Valid Input Range**: The `tanh()` function accepts any real number as input.
* **Null Handling**: If the input expression is `null`, the function returns `null`.
* **Symmetry**: The function is odd, meaning `tanh(-x) = -tanh(x)`.
* **Identity Value**: `tanh(0)` always returns `0.0`.
* **Result Range**: The output is always strictly between -1 and 1 (exclusive). As `x` approaches positive infinity, `tanh(x)` approaches `1.0`. As `x` approaches negative infinity, `tanh(x)` approaches `-1.0`.
* **Definition**: The hyperbolic tangent is defined as `sinh(x) / cosh(x)` or `(e^x - e^(-x)) / (e^x + e^(-x))`.
* **Common Use Cases**: This function is typically used within the `alter` stage for data normalization (squashing values to the range (-1, 1)), neural network activation functions, and scientific computations.

## Examples

### Example 1: Calculate hyperbolic tangent of literal values

**Goal**: Calculate the hyperbolic tangent for specific numeric literals to verify known mathematical results.

**XQL code**:

```sql
dataset = xdr_data
| limit 1
| alter result1 = tanh(0), result2 = tanh(1), result3 = tanh(-1)
| fields result1, result2, result3
```

**Explanation**: `tanh(0)` returns `0.0`. `tanh(1)` returns approximately `0.7616`, and `tanh(-1)` returns approximately `-0.7616`, demonstrating the odd symmetry of the function.

**Output**:

| RESULT1 | RESULT2 | RESULT3  |
| ------- | ------- | -------- |
| 0.0     | 0.76159 | -0.76159 |

### Example 2: Calculate hyperbolic tangent from a field value

**Goal**: Calculate the hyperbolic tangent of values stored in a dataset field.

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| alter tanh_result = tanh(numeric_value)
| fields event_id, numeric_value, tanh_result
| limit 3
```

**Explanation**: This query computes the hyperbolic tangent for each value in the `numeric_value` field. The result is always between -1 and 1, effectively normalizing the values. No filtering is needed since `tanh()` accepts any real number.

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | TANH\_RESULT |
| --------- | -------------- | ------------ |
| 101       | 0.0            | 0.0          |
| 102       | 1.0            | 0.76159      |
| 103       | 100.0          | 1.0          |

### Example 3: Use tanh for data normalization

**Goal**: Normalize large numeric values to the range (-1, 1) using the hyperbolic tangent function.

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| alter normalized_value = tanh(divide(numeric_value, 100))
| fields event_id, numeric_value, normalized_value
| limit 3
```

**Explanation**: This query first scales `numeric_value` by dividing by 100, then applies `tanh()` to squash the result into the range (-1, 1). This is a common normalization technique that preserves the sign and relative magnitude of values while bounding the output.

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | NORMALIZED\_VALUE |
| --------- | -------------- | ----------------- |
| 101       | 5.0            | 0.04996           |
| 102       | 500.0          | 1.0               |
| 103       | -200.0         | -0.96403          |

## Related articles

* **Stages**: [`alter`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/stages/alter.md), [`fields`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/stages/fields.md), [`limit`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/stages/limit.md)
* **Functions**: [`atanh`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/atanh.md), [`sinh`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/sinh.md), [`cosh`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/cosh.md), [`coth`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/coth.md)


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/tanh.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
