---
title: "fp64Guard(): function in Emulated f64, TypeShade API"
description: "fp64Guard, a function in Emulated f64. Pin the slot of the fp64 guard texture."
url: https://typeshade.dev/api/fp64guard/
language: en
---

# `fp64Guard()`

Function in Emulated `f64`

Pin the slot of the fp64 guard texture.

`import { fp64Guard } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function fp64Guard(at: { group: number; binding: number }): Fp64GuardHandle
```

## Parameters

**`at` `{ group: number; binding: number }`**

the `group` and `binding` to pin the guard texture to.

## Return value

`Fp64GuardHandle`

the [`Fp64GuardHandle`](https://typeshade.dev/api/fp64guardhandle/): `.binding` for `module({ uses })`, and `.type`.

## Exceptions

**[`SD0042`](https://typeshade.dev/reference/errors/sd0042/)**

A module declaring its own *fp64 binding with a different type or space fails emit with SD0042, and a declaration whose name starts with df64* or is one of the emitted DF64Vec2, DF64Vec3, DF64Vec4 structs collides with the emulation and fails with SD0043.

**[`SD0043`](https://typeshade.dev/reference/errors/sd0043/)**

A module declaring its own *fp64 binding with a different type or space fails emit with SD0042, and a declaration whose name starts with df64* or is one of the emitted DF64Vec2, DF64Vec3, DF64Vec4 structs collides with the emulation and fails with SD0043.

## Description

Most modules never call this: the guard is injected for you, and this exists for a fixed bind-group layout that needs it at a chosen `(group, binding)`.

Every module whose lowered code calls a guarded df64 helper gets a `texture_2d<f32>` binding named `_fp64` added by [`fp64Lower`](https://typeshade.dev/api/fp64lower/), deterministically at group 0 in the first free binding. A module whose only `f64` work is comparisons, widening and narrowing, negation, or scaling by a power-of-two literal calls none and gets no binding; a host that binds `_fp64` unconditionally should look for it in `reflect()` first. The host must bind a 1 by 1 texture whose single texel reads back exactly 1.0, an RGBA8 white texel or an R32F 1.0, and the shader multiplies the error-compensation terms by that texel.

It is a texture for a reason. WGSL permits reassociation, and Metal defaults to fast math, so without a value the compiler cannot see through, a downstream compiler can legally fold the emulation’s terms back to `f32` precision. A uniform is not enough either: some drivers specialize pipelines on observed uniform values and hot-swap a re-optimized variant that folds the terms anyway. The emitted shader reads `_fp64` from a bound texture instead of embedding its texel value as a compile-time constant.

Either way the binding appears in [`reflect`](https://typeshade.dev/api/reflect/) as an ordinary 2D texture, so a host building its bind group from the reflection creates it without special-casing.

The names around it are reserved. A module declaring its own `_fp64` binding with a different type or space fails emit with [`SD0042`](https://typeshade.dev/reference/errors/sd0042/), and a declaration whose name starts with `df64_` or is one of the emitted `DF64Vec2`, `DF64Vec3`, `DF64Vec4` structs collides with the emulation and fails with [`SD0043`](https://typeshade.dev/reference/errors/sd0043/).

## Examples

### Example

```ts
import { fp64Guard } from 'typeshade'
import { module } from 'typeshade/core/ir'

// Only needed when the host's bind-group layout fixes the slot.
const m = module({ uses: [U, fp64Guard({ group: 0, binding: 3 })], funcs: [k] })
```

## In the guide

- [fp64](https://typeshade.dev/guide/internals/fp64/)

## See also

- [`fp64Lower`](https://typeshade.dev/api/fp64lower/)
- [`reflect`](https://typeshade.dev/api/reflect/)
- [`Fp64GuardHandle`](https://typeshade.dev/api/fp64guardhandle/)
- [`f64T`](https://typeshade.dev/api/f64t/)
- [`FP64_GUARD_NAME`](https://typeshade.dev/api/fp64guardname/)

## Source

[`src/core/fp64/df64-lib.ts`, line 160](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/fp64/df64-lib.ts#L160), at commit af54ddad5
