---
title: "toI32(): IR builder function in typeshade/core/ir, TypeShade"
description: "toI32, an IR builder function in typeshade/core/ir. Convert to i32: the explicit numeric cast, where i32(/api/i32/) builds a literal from a JS number."
url: https://typeshade.dev/api/toi32/
language: en
---

# `toI32()`

Function in Builtins

Convert to `i32`: the explicit numeric cast, where `i32`(/api/`i32`/) builds a literal from a JS number.

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

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

## Syntax

```ts
const toI32: (x: ReadonlyNode<string> | number) => Node<"i32">
```

## Parameters

**`x` `ReadonlyNode<string> | number`**

## Return value

`Node<'i32'>`

## Description

Emits `i32(x)` on WGSL and `int(x)` on GLSL. Use it to turn a computed `f32` or `u32` node into an integer index or scrutinee.

## Examples

### Example

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

const idx = fn('idx', { u: f32T }, ({ u }) => toI32(u.mul(16)))
```

## Targets

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

## See also

- [`i32`](https://typeshade.dev/api/i32/)

## Source

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