{"id":13483464,"url":"https://github.com/petamoriken/float16","last_synced_at":"2026-02-21T10:31:48.342Z","repository":{"id":20838740,"uuid":"90376741","full_name":"petamoriken/float16","owner":"petamoriken","description":"Stage 3 IEEE 754 half-precision floating-point ponyfill","archived":false,"fork":false,"pushed_at":"2024-10-29T23:18:30.000Z","size":8967,"stargazers_count":96,"open_issues_count":6,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-30T01:51:01.719Z","etag":null,"topics":["binary16","float16","float16array","fp16","half-precision","ieee754","javascript","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/tc39/proposal-float16array","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/petamoriken.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-05T13:08:50.000Z","updated_at":"2024-10-29T23:18:34.000Z","dependencies_parsed_at":"2023-09-26T04:43:22.869Z","dependency_job_id":"d49e2643-6b06-4182-abf6-fc8a8fdff84f","html_url":"https://github.com/petamoriken/float16","commit_stats":{"total_commits":1266,"total_committers":6,"mean_commits":211.0,"dds":0.5774091627172195,"last_synced_commit":"c918f03d6e01a0f6db8fd6c44731a3e8ec4619ed"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petamoriken%2Ffloat16","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petamoriken%2Ffloat16/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petamoriken%2Ffloat16/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petamoriken%2Ffloat16/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petamoriken","download_url":"https://codeload.github.com/petamoriken/float16/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245863079,"owners_count":20684784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary16","float16","float16array","fp16","half-precision","ieee754","javascript","typescript"],"created_at":"2024-07-31T17:01:11.535Z","updated_at":"2026-02-21T10:31:48.336Z","avatar_url":"https://github.com/petamoriken.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003e [!NOTE]\n\u003e [Float16 proposal has been included in the ES2025 specification.](https://github.com/tc39/ecma262/pull/3532) In modern environments, there is no need to load this ponyfill.\n\u003e Please refer to [the Web Platform Status](https://webstatus.dev/features/float16array) for browser implementation status.\n\n# \u003ca href=\"https://github.com/petamoriken/float16\"\u003efloat16\u003c/a\u003e\n\n\u003cp align=\"center\"\u003e\n  IEEE 754 half-precision floating-point ponyfill for JavaScript\u003cbr\u003e\n  See \u003ca href=\"https://github.com/tc39/proposal-float16array\"\u003eTC39 proposal\u003c/a\u003e or \u003ca href=\"https://esdiscuss.org/topic/float16array\"\u003ethe archive of the ES Discuss Float16Array topic\u003c/a\u003e for details\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@petamoriken/float16\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/@petamoriken/float16?logo=npm\u0026amp;style=flat-square\" alt=\"npm downloads\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@petamoriken/float16\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@petamoriken/float16.svg?label=version\u0026amp;logo=npm\u0026amp;style=flat-square\" alt=\"npm version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://jsr.io/@petamoriken/float16\"\u003e\u003cimg src=\"https://jsr.io/badges/@petamoriken/float16?label=version\u0026amp;style=flat-square\" alt=\"jsr version\"\u003e\u003c/a\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://github.com/petamoriken/float16/blob/master/package.json\"\u003e\u003cimg src=\"https://img.shields.io/badge/dependencies-none-brightgreen?style=flat-square\" alt=\"dependencies\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/petamoriken/float16/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@petamoriken/float16.svg?style=flat-square\" alt=\"license\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/petamoriken/float16\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/gh/petamoriken/float16?logo=codecov\u0026amp;style=flat-square\" alt=\"codecov\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://saucelabs.com/u/petamoriken\"\u003e\n    \u003cimg src=\"https://app.saucelabs.com/browser-matrix/petamoriken.svg\" alt=\"Sauce Labs browser matrix\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Install\n\n### Node.js\n\n\u003e [!NOTE]\n\u003e Native float16 features are supported since\n\u003e [Node.js v24.0.0](https://nodejs.org/en/blog/release/v24.0.0).\n\n```console\nnpm install @petamoriken/float16\n```\n\n### Deno\n\n\u003e [!NOTE]\n\u003e Native float16 features are supported since\n\u003e [Deno v1.43](https://deno.com/blog/v1.43#v8-124).\n\n```console\ndeno add jsr:@petamoriken/float16\n```\n\n### Bun\n\n\u003e [!NOTE]\n\u003e Native float16 features are supported since\n\u003e [Bun v1.1.23](https://bun.sh/blog/bun-v1.1.23#float16array).\n\n```console\nbun add @petamoriken/float16\n```\n\n## Import\n\n### Node.js, Deno, Bun or Bundler\n\n```js\nimport {\n  Float16Array, isFloat16Array, isTypedArray,\n  getFloat16, setFloat16,\n  f16round,\n} from \"@petamoriken/float16\";\n```\n\n### Browser\n\nDeliver a `browser/float16.mjs` or `browser/float16.js` file in the npm package\nfrom your Web server with the JavaScript `Content-Type` HTTP header.\n\n```html\n\u003c!-- Module Scripts --\u003e\n\u003cscript type=\"module\"\u003e\n  import {\n    Float16Array, isFloat16Array, isTypedArray,\n    getFloat16, setFloat16,\n    f16round,\n  } from \"DEST/TO/float16.mjs\";\n\u003c/script\u003e\n```\n\n```html\n\u003c!-- Classic Scripts --\u003e\n\u003cscript src=\"DEST/TO/float16.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const {\n    Float16Array, isFloat16Array, isTypedArray,\n    getFloat16, setFloat16,\n    f16round,\n  } = float16;\n\u003c/script\u003e\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eOr, you can use \u003ca href=\"https://www.jsdelivr.com/package/npm/@petamoriken/float16\"\u003ejsDelivr CDN\u003c/a\u003e.\u003c/summary\u003e\n\n  ```html\n  \u003c!-- Module Scripts --\u003e\n  \u003cscript type=\"module\"\u003e\n    import {\n      Float16Array, isFloat16Array, isTypedArray,\n      getFloat16, setFloat16,\n      f16round,\n    } from \"https://cdn.jsdelivr.net/npm/@petamoriken/float16/+esm\";\n  \u003c/script\u003e\n  ```\n\n  ```html\n  \u003c!-- Classic Scripts --\u003e\n  \u003cscript src=\"https://cdn.jsdelivr.net/npm/@petamoriken/float16/browser/float16.min.js\"\u003e\u003c/script\u003e\n  \u003cscript\u003e\n    const {\n      Float16Array, isFloat16Array, isTypedArray,\n      getFloat16, setFloat16,\n      f16round,\n    } = float16;\n  \u003c/script\u003e\n  ```\n\n\u003c/details\u003e\n\n## Support engines\n\n**This package only requires ES2015 features** and does not use\nenvironment-dependent features (except for `inspect/`), so you can use it\nwithout any problems. It works fine with\n[the current officially supported versions of Node.js](https://github.com/nodejs/Release).\n\n`Float16Array` implemented by `Proxy` and `Reflect`, so IE11 is never supported\neven if you use polyfills.\n\n### Pre-transpiled JavaScript files (CommonJS, IIFE)\n\n`lib/` and `browser/` directories in the npm package have JavaScript files\nalready transpiled, and they have been tested automatically in the following\nenvironments:\n\n- Node.js: Active LTS\n- Firefox: last 2 versions and ESR\n- Chrome: last 2 versions\n- Safari: last 2 versions\n\n## API\n\n### `Float16Array`\n\n`Float16Array` is similar to `TypedArray` such as `Float32Array`\n([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)).\n\n```js\nconst array = new Float16Array([1.0, 1.1, 1.2, 1.3]);\nfor (const value of array) {\n  // 1, 1.099609375, 1.2001953125, 1.2998046875\n  console.log(value);\n}\n\n// Float16Array(4) [ 2, 2.19921875, 2.3984375, 2.599609375 ]\narray.map((value) =\u003e value * 2);\n```\n\n### `isFloat16Array`\n\n\u003e [!WARNING]\n\u003e This API returns `false` for ECMAScript's native `Float16Array`\n\n`isFloat16Array` is a utility function to check whether the value given as an\nargument is an instance of `Float16Array` or not.\n\n```js\nconst buffer = new ArrayBuffer(256);\n\n// true\nisFloat16Array(new Float16Array(buffer));\n\n// false\nisFloat16Array(new Float32Array(buffer));\nisFloat16Array(new Uint16Array(buffer));\nisFloat16Array(new DataView(buffer));\n```\n\n### `isTypedArray`\n\n`isTypedArray` is a utility function to check whether the value given as an\nargument is an instance of a type of `TypedArray` or not. Unlike\n`util.types.isTypedArray` in Node.js, this returns `true` for `Float16Array`.\n\n```js\nconst buffer = new ArrayBuffer(256);\n\n// true\nisTypedArray(new Float16Array(buffer));\nisTypedArray(new Float32Array(buffer));\nisTypedArray(new Uint16Array(buffer));\n\n// false\nisTypedArray(new DataView(buffer));\n```\n\n### `getFloat16`, `setFloat16`\n\n`getFloat16` and `setFloat16` are similar to `DataView` methods such as\n`DataView#getFloat32`\n([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32))\nand `DataView#setFloat32`\n([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)).\n\n```ts\ndeclare function getFloat16(view: DataView, byteOffset: number, littleEndian?: boolean): number;\ndeclare function setFloat16(view: DataView, byteOffset: number, value: number, littleEndian?: boolean): void;\n```\n\n```js\nconst buffer = new ArrayBuffer(256);\nconst view = new DataView(buffer);\n\nview.setUint16(0, 0x1234);\ngetFloat16(view, 0); // 0.0007572174072265625\n\n// You can append methods to DataView instance\nview.getFloat16 = (...args) =\u003e getFloat16(view, ...args);\nview.setFloat16 = (...args) =\u003e setFloat16(view, ...args);\n\nview.getFloat16(0); // 0.0007572174072265625\n\nview.setFloat16(0, Math.PI, true);\nview.getFloat16(0, true); // 3.140625\n```\n\n### `f16round` (alias: `hfround`)\n\n`f16round` is similar to `Math.fround`\n([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)).\nThis function returns nearest half-precision float representation of a number.\n\n```ts\ndeclare function f16round(x: number): number;\n```\n\n```js\nMath.fround(1.337); // 1.3370000123977661\nf16round(1.337); // 1.3369140625\n```\n\n## `Float16Array` limitations (edge cases)\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003ccode\u003eFloat16Array\u003c/code\u003e has some limitations, because it is impossible to completely reproduce the behavior of \u003ccode\u003eTypedArray\u003c/code\u003e. Be careful when checking if it is a \u003ccode\u003eTypedArray\u003c/code\u003e or not by using \u003ccode\u003eArrayBuffer.isView\u003c/code\u003e, and when using Web standards such as \u003ccode\u003estructuredClone\u003c/code\u003e and WebGL.\u003c/summary\u003e\n\n  ### Built-in functions\n\n  Built-in `TypedArray` objects use \"internal slots\" for built-in methods. Some\n  limitations exist because the `Proxy` object can't trap internal slots\n  ([explanation](https://javascript.info/proxy#built-in-objects-internal-slots)).\n\n  This package isn't polyfill, in other words, it doesn't change native global\n  functions and static/prototype methods.\n\n  E.g. `ArrayBuffer.isView` is the butlt-in method that checks if it has the\n  `[[ViewedArrayBuffer]]` internal slot. It returns `false` for `Proxy` object\n  such as `Float16Array` instance.\n\n  ```js\n  ArrayBuffer.isView(new Float32Array(10)); // true\n  ArrayBuffer.isView(new Float16Array(10)); // false\n  ```\n\n  ### The structured clone algorithm (Web Workers, IndexedDB, etc)\n\n  The structured clone algorithm copies complex JavaScript objects. It is used\n  internally when invoking `structuredClone()`, to transfer data between Web\n  Workers via `postMessage()`, storing objects with IndexedDB, or copying objects\n  for other APIs\n  ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)).\n\n  It can't clone `Proxy` object such as `Float16Array` instance, you need to\n  convert it to `Uint16Array` or deal with `ArrayBuffer` directly.\n\n  ```js\n  const array = new Float16Array([1.0, 1.1, 1.2]);\n  const cloned = structuredClone({ buffer: array.buffer });\n  ```\n\n  ### WebGL\n\n  WebGL requires `Uint16Array` for buffer or texture data whose types are\n  `gl.HALF_FLOAT` (WebGL 2) or `ext.HALF_FLOAT_OES` (WebGL 1 extension). Do not\n  apply the `Float16Array` object directly to `gl.bufferData` or `gl.texImage2D`\n  etc.\n\n  ```js\n  // WebGL 2 example\n  const vertices = new Float16Array([\n    -0.5, -0.5,  0,\n     0.5, -0.5,  0,\n     0.5,  0.5,  0,\n  ]);\n\n  const buffer = gl.createBuffer();\n  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n\n  // wrap in Uint16Array\n  gl.bufferData(gl.ARRAY_BUFFER, new Uint16Array(vertices.buffer), gl.STATIC_DRAW);\n  gl.vertexAttribPointer(location, 3, gl.HALF_FLOAT, false, 0, 0);\n\n  gl.bindBuffer(gl.ARRAY_BUFFER, null);\n  gl.enableVertexAttribArray(location);\n  ```\n\n  ### Others\n\n  See JSDoc comments in `src/Float16Array.mjs` for details. If you don't write\n  hacky code, you shouldn't have any problems.\n\n\u003c/details\u003e\n\n## `Float16Array` custom inspection\n\n\u003cdetails\u003e\n  \u003csummary\u003eProvides custom inspection for Node.js and Deno, which makes the results of \u003ccode\u003econsole.log\u003c/code\u003e more readable.\n  \u003c/summary\u003e\n\n  ```js\n  import { Float16Array } from \"@petamoriken/float16\";\n  import { customInspect } from \"@petamoriken/float16/inspect\";\n\n  Float16Array.prototype[Symbol.for(\"nodejs.util.inspect.custom\")] = customInspect;\n  ```\n\n  ```ts\n  import { Float16Array } from \"@petamoriken/float16\";\n  import { customInspect } from \"@petamoriken/float16/inspect\";\n\n  // deno-lint-ignore no-explicit-any\n  (Float16Array.prototype as any)[Symbol.for(\"nodejs.util.inspect.custom\")] = customInspect;\n  ```\n\n\u003c/details\u003e\n\n## Development\n\n\u003cdetails\u003e\n  \u003csummary\u003eManual build and test\u003c/summary\u003e\n\n  ### Manual build\n\n  This repository uses pnpm for package manager.\n  You may have to install pnpm in corepack.\n\n  Download devDependencies.\n\n  ```console\n  pnpm install\n  ```\n\n  Build `lib/`, `browser/` files.\n\n  ```console\n  pnpm run build\n  ```\n\n  Build `docs/` files (for browser test).\n\n  ```console\n  pnpm run docs\n  ```\n\n  ### Test\n\n  This repository uses pnpm for package manager.\n  You may have to install pnpm in corepack.\n\n  Download devDependencies.\n\n  ```console\n  pnpm install\n  ```\n\n  #### Node.js test\n\n  ```console\n  NODE_ENV=test pnpm build:lib\n  pnpm test\n  ```\n\n  #### Browser test\n\n  ```console\n  NODE_ENV=test pnpm build:browser\n  pnpm docs\n  ```\n\n  Access `docs/test/index.html` with browsers.\n\n  You can access current [test page](https://petamoriken.github.io/float16/test)\n  ([power-assert version](https://petamoriken.github.io/float16/test/power)) in\n  `master` branch.\n\n\u003c/details\u003e\n\n## License\n\nMIT License\n\nThis software contains productions that are distributed under\n[the Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).\nSpecifically, `index.d.ts` is modified from the original\n[TypeScript lib files](https://github.com/microsoft/TypeScript/tree/main/src/lib).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetamoriken%2Ffloat16","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetamoriken%2Ffloat16","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetamoriken%2Ffloat16/lists"}