---
title: "atan2(): IR builder function in typeshade/core/ir, TypeShade"
description: "atan2, an IR builder function in typeshade/core/ir. atan2(y, x): two-argument arctangent, resolving the full angle in [-π, π] from a (y, x) pair."
url: https://typeshade.dev/api/atan2/
language: en
---

# `atan2()`

Function in Builtins

`atan2`(y, x): two-argument arctangent, resolving the full angle in \[-π, π\] from a (y, x) pair.

`import { atan2 } from 'typeshade/core/ir'`

This export returns an IR node. A `"use typeshade"` file calls the builtin itself: [`atan2()`](https://typeshade.dev/reference/functions/atan2/)

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function atan2<K extends FloatKey>(y: ReadonlyNode<K>, x: NoInfer<ArithArg<K>>): Node<K>;
function atan2(y: number, x: ReadonlyNode<'f32'>): Node<'f32'>;
```

## Parameters

**`y` `ReadonlyNode<K>`**

**`x` `NoInfer<ArithArg<K>>`**

## Return value

`Node<K>`

## Description

Use it over the single-argument [`atan`](https://typeshade.dev/api/atan/) whenever the sign of `x` carries quadrant information, as when recovering a heading from a 2-D offset. Spelled `atan2` on WGSL and as the two-argument `atan(y, x)` on GLSL.

## Examples

### Example

```ts
import { fn, atan2, f32T } from 'typeshade/core/ir'

const heading = fn('heading', { dy: f32T, dx: f32T }, ({ dy, dx }) => atan2(dy, dx))
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `atan2(y, x)`. |
| GLSL ES 3.00 (WebGL2) | Supported | `atan(y, x)`. |
| CPU oracle | Supported | Evaluated in `f64` by the oracle. |

## See also

- [`atan2()`](https://typeshade.dev/reference/functions/atan2/)
- [`atan`](https://typeshade.dev/api/atan/)

## Source

[`src/core/ir/node.ts`, line 1383](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L1383), at commit af54ddad5
