---
title: "f32 / float: WGSL and GLSL examples, uses and input limits"
description: "A single-precision conversion rounds a number to a representable binary32 value. Use it for matching the precision used by ordinary shader arithmetic."
url: https://typeshade.dev/reference/functions/f32/
language: en
---

# `f32`

Function

A single-precision conversion rounds a number to a representable binary32 value.

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

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

## Compare examples

Adjacent large integers can round to the same binary32 value. Fractional inputs also round to a representable value.

**Example 1`f32(0.1)`**

**Result**

`0.10000000149011612`

**Example 2`f32(16777216)`**

**Result**

`16777216`

**Example 3`f32(16777217)`**

**Result**

`16777216`

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 matching the precision used by ordinary shader arithmetic.

## Inputs and limits

Large adjacent integers may become indistinguishable. Casting does not restore precision already lost.

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

- [`f64`](https://typeshade.dev/reference/functions/f64/)
- [`quantizeToF16`](https://typeshade.dev/reference/functions/quantizeToF16/)
- [`bitcast`](https://typeshade.dev/reference/functions/bitcast/)

**WGSL**

`f32(a)`

**GLSL ES 3.00**

`float(a)`

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

Casts a number to `f32` single-precision floating-point by inlining a literal value rounded to 32-bit precision.

## Syntax

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

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

`f32`

## Description

This is equivalent to `Math.fround(x)`.

## Targets

**WGSL**

`f32(a)`

**GLSL ES 3.00**

`float(a)`

## Examples

- [`path/tile-pattern/tile-pattern.shade.ts`](https://typeshade.dev/guide/examples/tile-pattern/)
- [`gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts`](https://typeshade.dev/guide/examples/capsule-corp-namek-class/)
- [`gallery/domain-warp-twin/domain-warp-twin.shade.ts`](https://typeshade.dev/guide/examples/domain-warp-twin/)
- [`gallery/hillshade-twin/hillshade-twin.shade.ts`](https://typeshade.dev/guide/examples/hillshade-twin/)
- [`gallery/julia-twin/julia-twin.shade.ts`](https://typeshade.dev/guide/examples/julia-twin/)
- [`gallery/kaleidoscope-twin/kaleidoscope-twin.shade.ts`](https://typeshade.dev/guide/examples/kaleidoscope-twin/)
- [`gallery/mandelbrot-twin/mandelbrot-twin.shade.ts`](https://typeshade.dev/guide/examples/mandelbrot-twin/)
- [`gallery/ocean-twin/ocean-twin.shade.ts`](https://typeshade.dev/guide/examples/ocean-twin/)
- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/guide/examples/path-tracer/)
- [`gallery/plasma-twin/plasma-twin.shade.ts`](https://typeshade.dev/guide/examples/plasma-twin/)
- [`gallery/rt-renderer-class/rt-renderer-class.shade.ts`](https://typeshade.dev/guide/examples/rt-renderer-class/)
- [`gallery/starfield-twin/starfield-twin.shade.ts`](https://typeshade.dev/guide/examples/starfield-twin/)
- [`gallery/tunnel-twin/tunnel-twin.shade.ts`](https://typeshade.dev/guide/examples/tunnel-twin/)
- [`gallery/voronoi-twin/voronoi-twin.shade.ts`](https://typeshade.dev/guide/examples/voronoi-twin/)
- [`gallery/fp64-burning-ship-twin/fp64-burning-ship-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-burning-ship-twin/)
- [`gallery/fp64-cancellation-twin/fp64-cancellation-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-cancellation-twin/)
- [`gallery/fp64-checker-plane-twin/fp64-checker-plane-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-checker-plane-twin/)
- [`gallery/fp64-clock-twin/fp64-clock-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-clock-twin/)
- [`gallery/fp64-deep-zoom-twin/fp64-deep-zoom-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-deep-zoom-twin/)
- [`gallery/fp64-julia-twin/fp64-julia-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-julia-twin/)
- [`gallery/fp64-lane-stripes/fp64-lane-stripes.shade.ts`](https://typeshade.dev/guide/examples/fp64-lane-stripes/)
- [`gallery/fp64-loran-twin/fp64-loran-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-loran-twin/)
- [`gallery/fp64-mandelbrot-de-twin/fp64-mandelbrot-de-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-mandelbrot-de-twin/)
- [`gallery/fp64-newton-twin/fp64-newton-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-newton-twin/)
- [`gallery/fp64-rtc-twin/fp64-rtc-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-rtc-twin/)
- [`gallery/fp64-sine-sweep-twin/fp64-sine-sweep-twin.shade.ts`](https://typeshade.dev/guide/examples/fp64-sine-sweep-twin/)
- [`gallery/array-literal-ramp/array-literal-ramp.shade.ts`](https://typeshade.dev/guide/examples/array-literal-ramp/)
- [`gallery/array-methods/array-methods.shade.ts`](https://typeshade.dev/guide/examples/array-methods/)
- [`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/class-builder/class-builder.shade.ts`](https://typeshade.dev/guide/examples/class-builder/)
- [`gallery/class-parts/class-parts.shade.ts`](https://typeshade.dev/guide/examples/class-parts/)
- [`gallery/class-syntax/class-syntax.shade.ts`](https://typeshade.dev/guide/examples/class-syntax/)
- [`gallery/clip-planes/clip-planes.shade.ts`](https://typeshade.dev/guide/examples/clip-planes/)
- [`gallery/closures/closures.shade.ts`](https://typeshade.dev/guide/examples/closures/)
- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/guide/examples/cube-array-gather/)
- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/guide/examples/cube-env/)
- [`gallery/cutout/cutout.shade.ts`](https://typeshade.dev/guide/examples/cutout/)
- [`gallery/feedback-trail/feedback-trail.shade.ts`](https://typeshade.dev/guide/examples/feedback-trail/)
- [`gallery/generic-helpers/generic-helpers.shade.ts`](https://typeshade.dev/guide/examples/generic-helpers/)
- [`gallery/hello-uniform/hello-uniform.shade.ts`](https://typeshade.dev/guide/examples/hello-uniform/)
- [`gallery/hello-uniform-struct/hello-uniform-struct.shade.ts`](https://typeshade.dev/guide/examples/hello-uniform-struct/)
- [`gallery/higher-order/higher-order.shade.ts`](https://typeshade.dev/guide/examples/higher-order/)
- [`gallery/id-pick/id-pick.shade.ts`](https://typeshade.dev/guide/examples/id-pick/)
- [`gallery/imported-noise/imported-noise.shade.ts`](https://typeshade.dev/guide/examples/imported-noise/)
- [`gallery/inferred-returns/inferred-returns.shade.ts`](https://typeshade.dev/guide/examples/inferred-returns/)
- [`gallery/integer-math/integer-math.shade.ts`](https://typeshade.dev/guide/examples/integer-math/)
- [`gallery/loop-kernel/loop-kernel.shade.ts`](https://typeshade.dev/guide/examples/loop-kernel/)
- [`gallery/loop-reduction/loop-reduction.shade.ts`](https://typeshade.dev/guide/examples/loop-reduction/)
- [`gallery/loops-over-data/loops-over-data.shade.ts`](https://typeshade.dev/guide/examples/loops-over-data/)
- [`gallery/module-const/module-const.shade.ts`](https://typeshade.dev/guide/examples/module-const/)
- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/guide/examples/msaa-resolve/)
- [`gallery/normal-matrix/normal-matrix.shade.ts`](https://typeshade.dev/guide/examples/normal-matrix/)
- [`gallery/packed-bytes/packed-bytes.shade.ts`](https://typeshade.dev/guide/examples/packed-bytes/)
- [`gallery/packing-bitcast/packing-bitcast.shade.ts`](https://typeshade.dev/guide/examples/packing-bitcast/)
- [`gallery/palette-const/palette-const.shade.ts`](https://typeshade.dev/guide/examples/palette-const/)
- [`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/)
- [`gallery/sample-branch/sample-branch.shade.ts`](https://typeshade.dev/guide/examples/sample-branch/)
- [`gallery/separable-blur/separable-blur.shade.ts`](https://typeshade.dev/guide/examples/separable-blur/)
- [`gallery/shadow-compare/shadow-compare.shade.ts`](https://typeshade.dev/guide/examples/shadow-compare/)
- [`gallery/storage-texture/storage-texture.shade.ts`](https://typeshade.dev/guide/examples/storage-texture/)
- [`gallery/textured-quad/textured-quad.shade.ts`](https://typeshade.dev/guide/examples/textured-quad/)
- [`gallery/twin-structs/twin-structs.shade.ts`](https://typeshade.dev/guide/examples/twin-structs/)
- [`gallery/uniform-array/uniform-array.shade.ts`](https://typeshade.dev/guide/examples/uniform-array/)

## See also

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