---
title: "pack2x16float / packHalf2x16: WGSL and GLSL function guide"
description: "Half-precision packing stores floating-point components as compact binary16 fields."
url: https://typeshade.dev/reference/functions/pack2x16float/
language: en
---

# `pack2x16float`

Function

Half-precision packing stores floating-point components as compact binary16 fields.

**Related names in other languages**

These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.

- GLSL: `packHalf2x16`

[Targets](https://typeshade.dev/reference/functions/pack2x16float/#targets)

## Compare examples

Compare the components, hexadecimal word, and recovered values. Notice which component occupies the low field.

**Example 1`pack2x16float(vec2(0, 1))`**

`0` `1`

Components in this example

**Result**

`0x3c000000`

Word in binary: `1006632960`

**Example 2`pack2x16float(vec2(-1, 0.5))`**

`-1` `0.5`

Components in this example

**Result**

`0x3800bc00`

Word in binary: `939572224`

**Example 3`pack2x16float(vec2(2, -2))`**

`2` `-2`

Components in this example

**Result**

`0xc0004000`

Word in binary: `3221241856`

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 to reduce storage or bandwidth when the reduced precision is acceptable.

## Inputs and limits

Binary16 has less range and precision than `f32`. The examples avoid halfway rounding cases; do not expect every input to survive a round trip.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`unpack2x16float`](https://typeshade.dev/reference/functions/unpack2x16float/)
- [`bitcast`](https://typeshade.dev/reference/functions/bitcast/)

**WGSL**

`pack2x16float(a)`

**GLSL ES 3.00**

`packHalf2x16(a)`

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Packs a `vec2` into two IEEE-754 binary16 halves of a `u32`, component 0 in the low 16 bits.

## Syntax

```ts
declare function pack2x16float(a0: vec2): u32
declare function pack2x16float(e: vec2): u32
```

## Parameters

- `e` `vec2`

## Return value

`u32`

## Description

`packHalf2x16` on GLSL ES 3.00.

## Targets

**WGSL**

`pack2x16float(a)`

**GLSL ES 3.00**

`packHalf2x16(a)`

## Examples

- [`gallery/packing-bitcast/packing-bitcast.shade.ts`](https://typeshade.dev/guide/examples/packing-bitcast/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#packing)
- [`pack2x16float()` in `typeshade/core/ir`](https://typeshade.dev/api/pack2x16float/)
