i32
On this page

i32

Function

A signed integer conversion removes the fractional part toward zero.

Related names in other languages

These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.

  • GLSL: int

Targets

Compare examples

Positive and negative inputs both lose their fractional part toward zero. Zero stays zero.

Example 1i32(-1.9)
Result
-1
Example 2i32(0)
Result
0
Example 3i32(1.9)
Result
1

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

When to use it

Use it for building integer indices from in-range numeric values.

Inputs and limits

The examples stay in range. Out-of-range literals are compile errors in this compiler; keep runtime values in range for portable shader code.

For shader input rules and precision, consult WGSL and GLSL ES 3.00.

WGSL
i32(a)
GLSL ES 3.00
int(a)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Casts a number to i32 signed 32-bit integer by truncating toward zero.

Syntax

declare function i32(): i32
declare function i32(x: number | bool): i32

A number in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

type f32 = number & { readonly [f32Tag]?: true }

A number you write as a type is inferred from its uses, and f32, i32 and u32 fix a width; the TypeScript constructs page carries that row with the compiler's emit.

Parameters

  • x optional number | bool

Return value

i32

Description

Literal values outside [-2^31, 2^31-1] are a compile error; at runtime, out-of-range values wrap via two's-complement.

Targets

WGSL
i32(a)
GLSL ES 3.00
int(a)

Examples

See also

Edit this page Report a problem