---
title: "i32 / int: WGSL·GLSL 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "소수 부분을 영 방향으로 버려 부호 있는 정수로 바꿉니다. 유효 범위 안의 숫자를 정수 인덱스로 바꿀 때 사용합니다. 예제는 유효 범위를 지킵니다. 이 컴파일러에서 범위를 벗어난 리터럴은 컴파일 오류입니다."
url: https://typeshade.dev/ko/reference/functions/i32/
language: ko
---

# `i32`

함수

소수 부분을 영 방향으로 버려 부호 있는 정수로 바꿉니다.

**다른 언어의 관련 이름**

관련 연산은 인수, 지원 범위와 의미가 다를 수 있습니다. 다른 언어의 이름을 TypeShade 별칭으로 사용할 수는 없습니다. 지원하는 형태와 제한은 대상 언어에 따라 다릅니다.

- GLSL: `int`

[대상별 출력](https://typeshade.dev/ko/reference/functions/i32/#targets)

## 예제 비교

양수와 음수 모두 소수 부분을 영 방향으로 버립니다. 영은 그대로 유지됩니다.

**예제 1`i32(-1.9)`**

**결과**

`-1`

**예제 2`i32(0)`**

**결과**

`0`

**예제 3`i32(1.9)`**

**결과**

`1`

예제는 설명용 계산 모델이며 GPU를 실행하지 않습니다. 정확한 호출 형식은 아래 컴파일러 참고 자료에서 설명합니다. 소수 결과는 표시할 때 반올림했습니다. 각 예제는 명시한 전제를 따릅니다. 실제 셰이더의 결과는 대상 언어의 정밀도와 실행 규칙에 따릅니다.

## 활용

유효 범위 안의 숫자를 정수 인덱스로 바꿀 때 사용합니다.

## 입력 범위와 주의사항

예제는 유효 범위를 지킵니다. 이 컴파일러에서 범위를 벗어난 리터럴은 컴파일 오류입니다. 이식성을 유지하려면 런타임 값도 유효 범위를 지켜야 합니다.

셰이더의 입력 규칙과 정밀도는 [WGSL](https://www.w3.org/TR/WGSL/)과 [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf)에서 규정합니다.

## 관련 함수

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

**WGSL**

`i32(a)`

**GLSL ES 3.00**

`int(a)`

시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 af54ddad5의 컴파일러가 쓴 영어 원문입니다.

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

## 구문

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

매개변수나 반환 위치에 쓰인 `number`는 스칼라가 들어갈 자리입니다. 앰비언트 파일은 GPU 스칼라를 브랜드가 붙은 number로 선언하고 그 브랜드는 선택이라서, 리터럴도 브랜드가 붙은 스칼라도 이 자리에 들어갑니다.

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

타입으로 쓴 `number`는 쓰이는 곳을 보고 추론하며, `f32`, `i32`, `u32`는 너비를 고정합니다. 그 행과 컴파일러가 낸 결과는 [TypeScript에서](https://typeshade.dev/ko/guide/language/from-typescript/) 페이지에 있습니다.

## 매개변수

- `x` 선택 사항 `number | bool`

## 반환값

`i32`

## 설명

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

## 대상별 출력

**WGSL**

`i32(a)`

**GLSL ES 3.00**

`int(a)`

## 예제

- [`path/tile-pattern/tile-pattern.shade.ts`](https://typeshade.dev/ko/guide/examples/tile-pattern/)
- [`path/palette/palette.shade.ts`](https://typeshade.dev/ko/guide/examples/palette/)
- [`path/image-blur/image-blur.shade.ts`](https://typeshade.dev/ko/guide/examples/image-blur/)
- [`gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts`](https://typeshade.dev/ko/guide/examples/capsule-corp-namek-class/)
- [`gallery/domain-warp-twin/domain-warp-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/domain-warp-twin/)
- [`gallery/kaleidoscope-twin/kaleidoscope-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/kaleidoscope-twin/)
- [`gallery/ocean-twin/ocean-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/ocean-twin/)
- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/ko/guide/examples/path-tracer/)
- [`gallery/starfield-twin/starfield-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/starfield-twin/)
- [`gallery/array-literal-ramp/array-literal-ramp.shade.ts`](https://typeshade.dev/ko/guide/examples/array-literal-ramp/)
- [`gallery/atomic-histogram/atomic-histogram.shade.ts`](https://typeshade.dev/ko/guide/examples/atomic-histogram/)
- [`gallery/bare-position/bare-position.shade.ts`](https://typeshade.dev/ko/guide/examples/bare-position/)
- [`gallery/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/ko/guide/examples/bit-bump/)
- [`gallery/bitfield-bands/bitfield-bands.shade.ts`](https://typeshade.dev/ko/guide/examples/bitfield-bands/)
- [`gallery/bool-select/bool-select.shade.ts`](https://typeshade.dev/ko/guide/examples/bool-select/)
- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/ko/guide/examples/cube-array-gather/)
- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/ko/guide/examples/cube-env/)
- [`gallery/default-args/default-args.shade.ts`](https://typeshade.dev/ko/guide/examples/default-args/)
- [`gallery/generic-class/generic-class.shade.ts`](https://typeshade.dev/ko/guide/examples/generic-class/)
- [`gallery/generic-helpers/generic-helpers.shade.ts`](https://typeshade.dev/ko/guide/examples/generic-helpers/)
- [`gallery/id-pick/id-pick.shade.ts`](https://typeshade.dev/ko/guide/examples/id-pick/)
- [`gallery/integer-math/integer-math.shade.ts`](https://typeshade.dev/ko/guide/examples/integer-math/)
- [`gallery/loop-on-cpu/loop-on-cpu.shade.ts`](https://typeshade.dev/ko/guide/examples/loop-on-cpu/)
- [`gallery/loops-over-data/loops-over-data.shade.ts`](https://typeshade.dev/ko/guide/examples/loops-over-data/)
- [`gallery/mixin-surface/mixin-surface.shade.ts`](https://typeshade.dev/ko/guide/examples/mixin-surface/)
- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/ko/guide/examples/msaa-resolve/)
- [`gallery/null-values/null-values.shade.ts`](https://typeshade.dev/ko/guide/examples/null-values/)
- [`gallery/optional-fields/optional-fields.shade.ts`](https://typeshade.dev/ko/guide/examples/optional-fields/)
- [`gallery/optional-values/optional-values.shade.ts`](https://typeshade.dev/ko/guide/examples/optional-values/)
- [`gallery/orbit-inout/orbit-inout.shade.ts`](https://typeshade.dev/ko/guide/examples/orbit-inout/)
- [`gallery/packed-bytes/packed-bytes.shade.ts`](https://typeshade.dev/ko/guide/examples/packed-bytes/)
- [`gallery/packing-bitcast/packing-bitcast.shade.ts`](https://typeshade.dev/ko/guide/examples/packing-bitcast/)
- [`gallery/pick-composite/pick-composite.shade.ts`](https://typeshade.dev/ko/guide/examples/pick-composite/)
- [`gallery/ray-class/ray-class.shade.ts`](https://typeshade.dev/ko/guide/examples/ray-class/)
- [`gallery/reference-parameters/reference-parameters.shade.ts`](https://typeshade.dev/ko/guide/examples/reference-parameters/)
- [`gallery/shadow-compare/shadow-compare.shade.ts`](https://typeshade.dev/ko/guide/examples/shadow-compare/)
- [`gallery/shape-inheritance/shape-inheritance.shade.ts`](https://typeshade.dev/ko/guide/examples/shape-inheritance/)
- [`gallery/storage-texture/storage-texture.shade.ts`](https://typeshade.dev/ko/guide/examples/storage-texture/)
- [`gallery/tuple-and-brand/tuple-and-brand.shade.ts`](https://typeshade.dev/ko/guide/examples/tuple-and-brand/)

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
- [내장 함수 표](https://typeshade.dev/ko/guide/language/builtins/#casts)
- [`typeshade/core/ir`의 `i32()`](https://typeshade.dev/ko/api/i32/)
