f64
Function
Widening an f32 preserves its value in a representation with more precision for later arithmetic.
Compare examples
Widening to f64 cannot recover precision lost when the value was first converted to f32. Exactly representable values stay unchanged.
Example 1f64(f32(0.1))
- Result
0.10000000149011612
Example 2f64(f32(1.5))
- Result
1.5
Example 3f64(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 reducing additional rounding during sensitive calculations.
Inputs and limits
Widening cannot recover lost input digits. This compiler emulates f64 in software; it is not a request for native hardware double precision.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Widens an f32 to the emulated double f64.
Syntax
declare function f64(x: number): f64A 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
-
xnumber
Return value
f64
Description
A value that is already f64 is returned as it is; cast an integer to f32 first.
Targets
- WGSL
- Rewritten into a pair of
f32lanes before either backend runs. - GLSL ES 3.00
- Rewritten into a pair of
f32lanes before either backend runs.
Examples
gallery/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-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.ts