---
title: "u32 / uint: WGSL and GLSL examples, uses and input limits"
description: "An unsigned integer conversion removes the fractional part toward zero for nonnegative in-range values. Use it for building unsigned counts and indices."
url: https://typeshade.dev/reference/functions/u32/
language: en
---

# `u32`

Function

An unsigned integer conversion removes the fractional part toward zero for nonnegative in-range values.

**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: `uint`

[Targets](https://typeshade.dev/reference/functions/u32/#targets)

## Compare examples

A nonnegative input loses its fractional part. The examples stay within the range of an unsigned integer.

**Example 1`u32(0)`**

**Result**

`0`

**Example 2`u32(1.9)`**

**Result**

`1`

**Example 3`u32(100.5)`**

**Result**

`100`

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 unsigned counts and indices.

## Inputs and limits

The examples stay nonnegative and in range. Out-of-range literals are compile errors; avoid negative or overflowing runtime inputs.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`i32`](https://typeshade.dev/reference/functions/i32/)
- [`trunc`](https://typeshade.dev/reference/functions/trunc/)
- [`bitcast`](https://typeshade.dev/reference/functions/bitcast/)

**WGSL**

`u32(a)`

**GLSL ES 3.00**

`uint(a)`

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

Casts a number to `u32` unsigned 32-bit integer by truncating toward zero.

## Syntax

```ts
declare function u32(): u32
declare function u32(x: number | bool): u32
```

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](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

## Parameters

- `x` optional `number | bool`

## Return value

`u32`

## Description

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

## Targets

**WGSL**

`u32(a)`

**GLSL ES 3.00**

`uint(a)`

## Examples

- [`path/image-blur/image-blur.shade.ts`](https://typeshade.dev/guide/examples/image-blur/)
- [`path/histogram/histogram.shade.ts`](https://typeshade.dev/guide/examples/histogram/)
- [`gallery/domain-warp-twin/domain-warp-twin.shade.ts`](https://typeshade.dev/guide/examples/domain-warp-twin/)
- [`gallery/kaleidoscope-twin/kaleidoscope-twin.shade.ts`](https://typeshade.dev/guide/examples/kaleidoscope-twin/)
- [`gallery/ocean-twin/ocean-twin.shade.ts`](https://typeshade.dev/guide/examples/ocean-twin/)
- [`gallery/starfield-twin/starfield-twin.shade.ts`](https://typeshade.dev/guide/examples/starfield-twin/)
- [`gallery/atomic-histogram/atomic-histogram.shade.ts`](https://typeshade.dev/guide/examples/atomic-histogram/)
- [`gallery/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/guide/examples/bit-bump/)
- [`gallery/block-scope/block-scope.shade.ts`](https://typeshade.dev/guide/examples/block-scope/)
- [`gallery/integer-math/integer-math.shade.ts`](https://typeshade.dev/guide/examples/integer-math/)
- [`gallery/loop-reduction/loop-reduction.shade.ts`](https://typeshade.dev/guide/examples/loop-reduction/)
- [`gallery/module-const/module-const.shade.ts`](https://typeshade.dev/guide/examples/module-const/)
- [`gallery/packed-bytes/packed-bytes.shade.ts`](https://typeshade.dev/guide/examples/packed-bytes/)
- [`gallery/particle-step/particle-step.shade.ts`](https://typeshade.dev/guide/examples/particle-step/)
- [`gallery/private-state/private-state.shade.ts`](https://typeshade.dev/guide/examples/private-state/)
- [`gallery/rng-method/rng-method.shade.ts`](https://typeshade.dev/guide/examples/rng-method/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#casts)
- [`u32()` in `typeshade/core/ir`](https://typeshade.dev/api/u32/)
