f64
On this page

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.

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): f64

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 number

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 f32 lanes before either backend runs.
GLSL ES 3.00
Rewritten into a pair of f32 lanes before either backend runs.

Examples

See also

Edit this page Report a problem