---
title: "Float16Array in JavaScript"
description: "Float16Array stores 16-bit floating point numbers in half the memory of a Float32Array. How it works, when to use it and which browsers support it."
canonical: "https://www.trevorlasn.com/blog/float16array-javascript"
author: "Trevor I. Lasn"
published: "2025-04-14"
last-updated: "2025-04-14"
topics: ["JavaScript"]
---

# Float16Array in JavaScript

Float16Array stores 16-bit floating point numbers in half the memory of a Float32Array. How it works, when to use it and which browsers support it.

By Trevor I. Lasn · Published 2025-04-14 · https://www.trevorlasn.com/blog/float16array-javascript

`Float16Array` is a new type of array in JavaScript that stores 16-bit (2-byte) floating point numbers. It joins the existing family of TypedArrays like `Int8Array`, `Uint8Array`, `Float32Array`, and `Float64Array`

[Browser support for `float16array` on webstatus.dev](https://webstatus.dev/features/float16array)

If you've never used TypedArrays before, **think of them as specialized arrays that can only contain specific types of numbers.**

Unlike regular JavaScript arrays that can mix strings, objects, and numbers, TypedArrays are fixed-size, memory-efficient arrays dedicated to numeric data.

Here's how you'd create and use a `Float16Array`

```javascript title="JavaScript"
// Create a Float16Array with 4 elements
const myArray = new Float16Array(4);

myArray[0] = 1.5;
myArray[1] = 42.0;
myArray[2] = 0.333;
myArray[3] = -27.5;

console.log(myArray); // Float16Array [1.5, 42, 0.3330078125, -27.5]
```

Notice something interesting with the third value? `0.333` became `0.3330078125`. This happens because 16-bit floating point numbers have limited precision compared to JavaScript's standard 64-bit numbers.

You might wonder: "We already have `Float32Array` and `Float64Array`, so why do we need a 16-bit version?"

The answer comes down to three things: memory, performance, and compatibility.

| TypedArray      | Element Type | Bytes Per Element | Description                 | Value Range                                | Precision              |
|-----------------|--------------|-------------------|-----------------------------|--------------------------------------------|------------------------|
| `Float16Array`  | 16-bit float | 2                 | 16-bit IEEE floating point  | ±65,504                                    | ~3 decimal digits      |
| `Float32Array`  | 32-bit float | 4                 | 32-bit IEEE floating point  | ±3.4×10^38                                 | ~7 decimal digits      |
| `Float64Array`  | 64-bit float | 8                 | 64-bit IEEE floating point  | ±1.8×10^308                                | ~15 decimal digits     |

A `Float16Array` uses half the memory of a `Float32Array`. If you're working with large datasets, this can make a significant difference.

```javascript title="JavaScript"
const smallArray = new Float16Array(1000000); // ~2MB
const largeArray = new Float32Array(1000000); // ~4MB
```

For applications processing millions of values, this memory saving can be crucial. In certain contexts, especially with GPU-accelerated computing, 16-bit floats can be processed more efficiently than 32-bit or 64-bit numbers. Newer GPUs often have specialized hardware for handling 16-bit floating point math, making operations potentially faster.

### References
- [TC39 Float16Array](https://tc39.es/proposal-float16array/)
- [Float16Array Proposal](https://github.com/tc39/proposal-float16array)
