pack2x16float
On this page

pack2x16float()

Function in Builtins

Pack a vec2<f32> into a u32 as two IEEE-754 binary16 (half) values, component 0 in the 16 low bits.

import { pack2x16float } from 'typeshade'

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

Syntax

const pack2x16float: (v: ReadonlyNode<"vec2<f32>">) => Node<"u32">

Parameters

v ReadonlyNode<'vec2<f32>'>

Return value

Node<'u32'>

Description

Native on both targets (WGSL pack2x16float, GLSL ES 3.00 packHalf2x16); a value outside binary16’s finite range (|x| > 65504) overflows to ±∞ per IEEE conversion. A compact carrier for a pair where 8-bit unorm quantisation is too coarse and two full f32 components are too wide; unpack2x16float restores the rounded pair.

Examples

Example

import { fn, pack2x16float, vec2fT } from 'typeshade'
const packed = fn('packed', { hv: vec2fT }, ({ hv }) => pack2x16float(hv))

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

pack2x16float(v).

GLSL ES 3.00 (WebGL2) Supported

packHalf2x16(v).

CPU oracle Supported

Evaluated in f64 by the oracle.

See also

Source

src/core/ir/node.ts, line 1894, at commit 26de7be8

Edit this page Report a problem