# @webassemblyjs/floating-point-hex-parser

> A function to parse floating point hexadecimal strings as defined by the WebAssembly specification

Latest version **1.14.1** (published 2024-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @webassemblyjs/floating-point-hex-parser
pnpm add @webassemblyjs/floating-point-hex-parser
yarn add @webassemblyjs/floating-point-hex-parser
bun add @webassemblyjs/floating-point-hex-parser
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.14.1 |
| Published | 2024-11-06 |
| First published | 2018-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 834 |
| Author | Mauro Bringolf |
| Maintainers | xtuc |
| Keywords | webassembly, floating-point |

## Links

- npm: https://www.npmjs.com/package/@webassemblyjs/floating-point-hex-parser
- Repository: https://github.com/xtuc/webassemblyjs
- Homepage: https://github.com/xtuc/webassemblyjs#readme
- Issues: https://github.com/xtuc/webassemblyjs/issues
- npm.io page: https://npm.io/package/@webassemblyjs/floating-point-hex-parser

## Recent versions

- 1.14.1 (latest) — 2024-11-06
- 1.14.0 — 2024-11-06
- 1.13.2 — 2024-11-06
- 1.13.1 — 2024-11-06
- 1.13.0 — 2024-11-06
- 1.12.1 — 2024-03-13
- 1.12.0 — 2024-03-13
- 1.11.6 — 2023-05-09
- 1.11.5 — 2023-04-16
- 1.11.4 — 2022-07-02
- 1.11.1 — 2021-07-05
- 1.11.0 — 2021-01-07
- 1.10.1 — 2021-01-07
- 1.10.0 — 2021-01-07
- 1.9.1 — 2020-10-03
- … 57 more at https://npm.io/package/@webassemblyjs/floating-point-hex-parser/versions

## README

# Parser function for floating point hexadecimals

[![license](https://img.shields.io/github/license/maurobringolf/@webassemblyjs/floating-point-hex-parser.svg)]()
[![GitHub last commit](https://img.shields.io/github/last-commit/maurobringolf/@webassemblyjs/floating-point-hex-parser.svg)]()
[![npm](https://img.shields.io/npm/v/@webassemblyjs/floating-point-hex-parser.svg)]()

> A JavaScript function to parse floating point hexadecimals as defined by the [WebAssembly specification](https://webassembly.github.io/spec/core/text/values.html#text-hexfloat).

## Usage

```javascript
import parseHexFloat from '@webassemblyjs/floating-point-hex-parser'

parseHexFloat('0x1p-1')               // 0.5
parseHexFloat('0x1.921fb54442d18p+2') // 6.283185307179586
```

## Tests

This module is tested in two ways. The first one is through a small set of test cases that can be found in [test/regular.test.js](https://github.com/maurobringolf/@webassemblyjs/floating-point-hex-parser/blob/master/test/regular.test.js). The second one is non-deterministic (sometimes called *fuzzing*):

1. Generate a random IEEE754 double precision value `x`.
1. Compute its representation `y` in floating point hexadecimal format using the C standard library function `printf` since C supports this format.
1. Give both values to JS testcase and see if `parseHexFloat(y) === x`.

By default one `npm test` run tests 100 random samples. If you want to do more, you can set the environment variable `FUZZ_AMOUNT` to whatever number of runs you'd like. Because it uses one child process for each sample, it is really slow though. For more details about the randomized tests see [the source](https://github.com/maurobringolf/@webassemblyjs/floating-point-hex-parser/tree/master/test/fuzzing).

## Links

* [maurobringolf.ch/2017/12/hexadecimal-floating-point-notation/](https://maurobringolf.ch/2017/12/hexadecimal-floating-point-notation/)

* [github.com/xtuc/js-webassembly-interpreter/issues/32](https://github.com/xtuc/js-webassembly-interpreter/issues/32)

* [github.com/WebAssembly/design/issues/292](https://github.com/WebAssembly/design/issues/292)

---
_Source: https://npm.io/package/@webassemblyjs/floating-point-hex-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
