This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/@webassemblyjs/floating-point-hex-parser
2019-08-11 20:48:02 +02:00
..
esm Update Framework 2019-08-11 20:48:02 +02:00
lib Update Framework 2019-08-11 20:48:02 +02:00
LICENSE Update Framework 2019-08-11 20:48:02 +02:00
package.json Update Framework 2019-08-11 20:48:02 +02:00
README.md Update Framework 2019-08-11 20:48:02 +02:00

Parser function for floating point hexadecimals

license GitHub last commit npm

A JavaScript function to parse floating point hexadecimals as defined by the WebAssembly specification.

Usage

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. The second one is non-deterministic (sometimes called fuzzing):

  1. Generate a random IEEE754 double precision value x.
  2. Compute its representation y in floating point hexadecimal format using the C standard library function printf since C supports this format.
  3. 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.