f32
On this page

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

Compare examples

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

Example 1f32(0.1)
Result
0.10000000149011612
Example 2f32(16777216)
Result
16777216
Example 3f32(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 and GLSL ES 3.00.

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

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 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

See also

Edit this page Report a problem