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'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
const toI32: (x: ReadonlyNode<string> | number) => Node<"i32">Parameters
xReadonlyNode<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
import { fn, toI32, f32T } from 'typeshade'
const idx = fn('idx', { u: f32T }, ({ u }) => toI32(u.mul(16)))Targets
| Target | Support | Notes |
|---|---|---|
| WGSL (WebGPU) | Supported |
|
| GLSL ES 3.00 (WebGL2) | Supported |
|
| CPU oracle | Supported | Evaluated in f64 by the oracle. |
See also
Source
src/core/ir/node.ts, line 2411, at commit 26de7be8