recommendFp64Flavor()
Function in Emulated f64
Pick the df64 flavour a device needs for correct results, from whatever identifying signals a host has.
import { recommendFp64Flavor } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function recommendFp64Flavor(s: Fp64FlavorSignals): Fp64FlavorParameters
sFp64FlavorSignalsthe device signals the host was able to collect.
Return value
'integer' on an Apple or Metal-backed context, 'float' everywhere else.
Description
Pass the result as EmitOptions.fp64Flavor.
The flavour differs by device because of one operation. The df64 multiply relies on error
terms that are algebraically zero, and a compiler allowed to reassociate can cancel them.
On Apple GPUs, where Metal runs underneath whether the path is WebGPU or WebGL2 through
ANGLE, the shader compiler defaults to fast math and collapses that multiply at any
large-magnitude cancellation, and no in-shader barrier prevents it. sin and cos are
built on that multiply, so they inherit the same fragility there. An Apple signal therefore
selects 'integer', which does the same arithmetic through integer primitives fast math
cannot touch, and every other device gets 'float', which is correct on those devices and
cheaper.
D3D11 through ANGLE gets 'float' as well. Its compiler can fold very deep synthetic df64
expression trees, but the float flavour’s renormalisation holds on the chains that occur in
practice, and compiling the fully inlined integer bodies there is expensive enough to reset
the device.
The library cannot see a GPU, so the signals come from the caller: a WebGPU adapter’s
info, a WebGL2 UNMASKED_RENDERER_WEBGL string, a user agent. All are optional, any
single Apple signal selects 'integer', and passing none returns 'float'.
Examples
Example
import { recommendFp64Flavor, emitModule } from 'typeshade'
const fp64Flavor = recommendFp64Flavor({ adapterInfo: adapter.info, userAgent: navigator.userAgent })const wgsl = emitModule(MODULE, { fp64Flavor })In the guide
See also
Source
src/core/fp64/flavor-select.ts, line 102, at commit 26de7be8