---
title: "i32(): IR builder function in typeshade/core/ir, TypeShade"
description: "i32, an IR builder function in typeshade/core/ir. An i32 literal node."
url: https://typeshade.dev/api/i32/
language: en
---

# `i32()`

Function in Values

An `i32` literal node.

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

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

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

## Syntax

```ts
function i32(v: number): Node<'i32'>;
function i32(x: ReadonlyNode<ScalarCastSource>): Node<'i32'>;
```

## Parameters

**`v` `number`**

## Return value

`Node<'i32'>`

## Exceptions

**`TypeError`**

`v` is neither a JS number nor a scalar node.

**[`SD0116`](https://typeshade.dev/reference/errors/sd0116/)**

[`SD0116`](https://typeshade.dev/reference/errors/sd0116/) when the node operand is not a scalar.

## Description

Use it over the `f32` default wherever a value must type-check as a signed integer: array and loop indices, `matchExpr` and `matchEnum` scrutinees, texture layer arguments.

A Node argument is a cast instead: `i32(x)` converts, the free-function twin of `x.i32()`. It builds what [`toI32`](https://typeshade.dev/api/toi32/) builds, and its operand is bounded to a scalar.

## Examples

### Example

```ts
import { i32 } from 'typeshade/core/ir'

const zero = i32(0)  // Node<'i32'>
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `i32(a)`. |
| GLSL ES 3.00 (WebGL2) | Supported | `int(a)`. |
| CPU oracle | Supported | Evaluated in `f64` by the oracle. |

## In the guide

- [Values and mutation](https://typeshade.dev/guide/internals/values-and-mutation/)
- [Control flow](https://typeshade.dev/guide/internals/control-flow/)
- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)
- [fp64](https://typeshade.dev/guide/internals/fp64/)
- [Migrating a GLSL shader](https://typeshade.dev/guide/internals/migrating-a-glsl-shader/)

## See also

- [`i32()`](https://typeshade.dev/reference/functions/i32/)
- [`toI32`](https://typeshade.dev/api/toi32/)

## Source

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