> 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/csc.md).

# csc

Use the `csc()` function to calculate the cosecant of a numeric value specified in radians. The cosecant is the reciprocal of the sine function.

## Syntax

```sql
csc(<numeric_expression>)
```

## Parameters

| Name                 | Type           | Required | Description                                                                                              |
| -------------------- | -------------- | -------- | -------------------------------------------------------------------------------------------------------- |
| `numeric_expression` | integer, float | Yes      | The angle in radians for which to calculate the cosecant. The value must not be zero or a multiple of π. |

## Returns

**Type**: float

**Description**: The `csc()` function returns the cosecant of the input angle, which is equivalent to `1 / sin(x)`. 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 `csc()` function accepts any real number except values where `sin(x) = 0` (i.e., multiples of π, including zero), where the cosecant is undefined.
* **Undefined Values**: At `x = 0` and multiples of π, the function returns `infinity`, `NaN`, or `null` since the cosecant is undefined at these points.
* **Null Handling**: If the input expression is `null`, the function returns `null`.
* **Relationship**: `csc(x) = 1 / sin(x)`.
* **Result Range**: The result is always ≤ -1 or ≥ 1 (never between -1 and 1).
* **Common Use Cases**: This function is typically used within the `alter` stage for trigonometric calculations, wave analysis, and engineering computations.

## Examples

### Example 1: Calculate cosecant of literal values

**Goal**: Calculate the cosecant for specific radian values to verify known mathematical results.

**XQL code**:

```sql
dataset = xdr_data
| limit 1
| alter result1 = csc(divide(pi(), 2)), result2 = csc(divide(pi(), 6)), result3 = csc(1)
| fields result1, result2, result3
```

**Explanation**: You use `csc()` on three different radian values. `csc(π/2)` returns `1.0` (since `sin(π/2) = 1`), `csc(π/6)` returns `2.0` (since `sin(π/6) = 0.5`), and `csc(1)` returns approximately `1.1884`.

**Output**:

| RESULT1 | RESULT2 | RESULT3 |
| ------- | ------- | ------- |
| 1.0     | 2.0     | 1.18840 |

### Example 2: Calculate cosecant from a field value

**Goal**: Calculate the cosecant of values stored in a dataset field, filtering out values near zero.

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| filter numeric_value != 0
| alter csc_val = csc(numeric_value)
| fields event_id, numeric_value, csc_val
| limit 3
```

**Explanation**: This query filters out zero values (where cosecant is undefined), then computes the cosecant for each remaining value in the `numeric_value` field.

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | CSC\_VAL |
| --------- | -------------- | -------- |
| 101       | 0.5            | 2.08583  |
| 102       | 1.0            | 1.18840  |
| 103       | 1.5708         | 1.0      |

### Example 3: Verify cosecant as reciprocal of sine

**Goal**: Demonstrate that `csc(x)` equals `1 / sin(x)` by computing both and comparing.

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| filter numeric_value != 0
| alter csc_val = csc(numeric_value)
| alter reciprocal_sin = divide(1, sin(numeric_value))
| fields event_id, numeric_value, csc_val, reciprocal_sin
| limit 3
```

**Explanation**: This query computes both `csc(numeric_value)` and `1 / sin(numeric_value)` to verify they produce the same result, confirming the mathematical identity `csc(x) = 1 / sin(x)`.

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | CSC\_VAL | RECIPROCAL\_SIN |
| --------- | -------------- | -------- | --------------- |
| 101       | 0.5            | 2.08583  | 2.08583         |
| 102       | 1.0            | 1.18840  | 1.18840         |
| 103       | 1.5708         | 1.0      | 1.0             |

## Related articles

* **Stages**: [`alter`](/xql-command-reference-guide/readme/stages/alter.md), [`filter`](/xql-command-reference-guide/readme/stages/filter.md), [`fields`](/xql-command-reference-guide/readme/stages/fields.md), [`limit`](/xql-command-reference-guide/readme/stages/limit.md)
* **Functions**: [`sin()`](/xql-command-reference-guide/readme/functions/sin.md), [`sec()`](/xql-command-reference-guide/readme/functions/sec.md), `csch()`, [`cot()`](/xql-command-reference-guide/readme/functions/cot.md)
* **Datasets**: [`xdr_data`](https://docs-cortex.paloaltonetworks.com/r/Cortex-XQL-Schema-Reference-Guide/Introduction)


---

# 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://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/csc.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.
