source: trip-planner-front/node_modules/@webassemblyjs/floating-point-hex-parser/README.md@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[6a3a178]1# Parser function for floating point hexadecimals
2
3[![license](https://img.shields.io/github/license/maurobringolf/@webassemblyjs/floating-point-hex-parser.svg)]()
4[![GitHub last commit](https://img.shields.io/github/last-commit/maurobringolf/@webassemblyjs/floating-point-hex-parser.svg)]()
5[![npm](https://img.shields.io/npm/v/@webassemblyjs/floating-point-hex-parser.svg)]()
6
7> 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).
8
9## Usage
10
11```javascript
12import parseHexFloat from '@webassemblyjs/floating-point-hex-parser'
13
14parseHexFloat('0x1p-1') // 0.5
15parseHexFloat('0x1.921fb54442d18p+2') // 6.283185307179586
16```
17
18## Tests
19
20This 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*):
21
221. Generate a random IEEE754 double precision value `x`.
231. Compute its representation `y` in floating point hexadecimal format using the C standard library function `printf` since C supports this format.
241. Give both values to JS testcase and see if `parseHexFloat(y) === x`.
25
26By 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).
27
28## Links
29
30* [maurobringolf.ch/2017/12/hexadecimal-floating-point-notation/](https://maurobringolf.ch/2017/12/hexadecimal-floating-point-notation/)
31
32* [github.com/xtuc/js-webassembly-interpreter/issues/32](https://github.com/xtuc/js-webassembly-interpreter/issues/32)
33
34* [github.com/WebAssembly/design/issues/292](https://github.com/WebAssembly/design/issues/292)
Note: See TracBrowser for help on using the repository browser.