# FloatPacking

Class · category: Math

Source: https://github.com/playcanvas/engine/blob/f059dc005842f76e052cdf44d8370c8c7ec475ac/src/core/math/float-packing.js#L24

Utility static class providing functionality to pack float values to various storage
representations.

[float2Half](https://api.playcanvas.com/engine/classes/FloatPacking.md#float2half) converts a JavaScript number to the 16-bit half-float encoding used by
half-precision textures and vertex formats, so float data can be uploaded to the GPU at half the
size.

**Example**

```ts
// Fill a half-float buffer from an array of numbers
const halves = new Uint16Array(values.length);
for (let i = 0; i < values.length; i++) {
    halves[i] = FloatPacking.float2Half(values[i]);
}
```

## Methods

### float2Half

```ts
static float2Half(value: number): number
```

Packs a float to a 16-bit half-float representation used by the GPU.

**Parameters**

- `value` (`number`): The float value to pack.

**Returns** `number`: The 16-bit half-float representation as an integer.

**Example**

```ts
const half = FloatPacking.float2Half(1.5);
```
