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
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.
Related functions
- 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(): f32declare function f32(x: number | bool): f32A 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
-
xoptionalnumber | 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.tsgallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.tsgallery/domain-warp-twin/domain-warp-twin.shade.tsgallery/hillshade-twin/hillshade-twin.shade.tsgallery/julia-twin/julia-twin.shade.tsgallery/kaleidoscope-twin/kaleidoscope-twin.shade.tsgallery/mandelbrot-twin/mandelbrot-twin.shade.tsgallery/ocean-twin/ocean-twin.shade.tsgallery/path-tracer/path-tracer.shade.tsgallery/plasma-twin/plasma-twin.shade.tsgallery/rt-renderer-class/rt-renderer-class.shade.tsgallery/starfield-twin/starfield-twin.shade.tsgallery/tunnel-twin/tunnel-twin.shade.tsgallery/voronoi-twin/voronoi-twin.shade.tsgallery/fp64-burning-ship-twin/fp64-burning-ship-twin.shade.tsgallery/fp64-cancellation-twin/fp64-cancellation-twin.shade.tsgallery/fp64-checker-plane-twin/fp64-checker-plane-twin.shade.tsgallery/fp64-clock-twin/fp64-clock-twin.shade.tsgallery/fp64-deep-zoom-twin/fp64-deep-zoom-twin.shade.tsgallery/fp64-julia-twin/fp64-julia-twin.shade.tsgallery/fp64-lane-stripes/fp64-lane-stripes.shade.tsgallery/fp64-loran-twin/fp64-loran-twin.shade.tsgallery/fp64-mandelbrot-de-twin/fp64-mandelbrot-de-twin.shade.tsgallery/fp64-newton-twin/fp64-newton-twin.shade.tsgallery/fp64-rtc-twin/fp64-rtc-twin.shade.tsgallery/fp64-sine-sweep-twin/fp64-sine-sweep-twin.shade.tsgallery/array-literal-ramp/array-literal-ramp.shade.tsgallery/array-methods/array-methods.shade.tsgallery/bit-bump/bit-bump.shade.tsgallery/block-scope/block-scope.shade.tsgallery/class-builder/class-builder.shade.tsgallery/class-parts/class-parts.shade.tsgallery/class-syntax/class-syntax.shade.tsgallery/clip-planes/clip-planes.shade.tsgallery/closures/closures.shade.tsgallery/cube-array-gather/cube-array-gather.shade.tsgallery/cube-env/cube-env.shade.tsgallery/cutout/cutout.shade.tsgallery/feedback-trail/feedback-trail.shade.tsgallery/generic-helpers/generic-helpers.shade.tsgallery/hello-uniform/hello-uniform.shade.tsgallery/hello-uniform-struct/hello-uniform-struct.shade.tsgallery/higher-order/higher-order.shade.tsgallery/id-pick/id-pick.shade.tsgallery/imported-noise/imported-noise.shade.tsgallery/inferred-returns/inferred-returns.shade.tsgallery/integer-math/integer-math.shade.tsgallery/loop-kernel/loop-kernel.shade.tsgallery/loop-reduction/loop-reduction.shade.tsgallery/loops-over-data/loops-over-data.shade.tsgallery/module-const/module-const.shade.tsgallery/msaa-resolve/msaa-resolve.shade.tsgallery/normal-matrix/normal-matrix.shade.tsgallery/packed-bytes/packed-bytes.shade.tsgallery/packing-bitcast/packing-bitcast.shade.tsgallery/palette-const/palette-const.shade.tsgallery/private-state/private-state.shade.tsgallery/rng-method/rng-method.shade.tsgallery/sample-branch/sample-branch.shade.tsgallery/separable-blur/separable-blur.shade.tsgallery/shadow-compare/shadow-compare.shade.tsgallery/storage-texture/storage-texture.shade.tsgallery/textured-quad/textured-quad.shade.tsgallery/twin-structs/twin-structs.shade.tsgallery/uniform-array/uniform-array.shade.ts