---
title: "abs(): IR builder function in typeshade/core/ir, TypeShade"
description: "abs, an IR builder function in typeshade/core/ir. abs(x): absolute value, component-wise."
url: https://typeshade.dev/api/abs/
language: en
---

# `abs()`

Function in Builtins

`abs(x)`: absolute value, component-wise.

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

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

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

## Syntax

```ts
const abs: <K extends FloatKey | Float64Key | IntKey>(
  x: ReadonlyNode<K>,
) => Node<K>
```

## Parameters

**`x` `ReadonlyNode<K>`**

## Return value

`Node<K>`

## Description

An unsigned operand takes the `absU` id rather than the portable `abs` one, because GLSL ES 3.00 has no `abs(uint)` overload and a WebGL2 driver refuses the call. The choice is `divergentIntegerId`, shared with the `"use typeshade"` front end so both authoring surfaces emit the same thing; every other operand keeps the portable spelling.

## Examples

### Example

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

const magnitude = fn('magnitude', { x: f32T }, ({ x }) => abs(x))
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `abs(a)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| GLSL ES 3.00 (WebGL2) | Supported | `abs(a)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| CPU oracle | Supported | Evaluated in `f64` by the oracle. |

## In the guide

- [fp64](https://typeshade.dev/guide/internals/fp64/)

## See also

- [`abs()`](https://typeshade.dev/reference/functions/abs/)

## Source

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