🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

@webassemblyjs/floating-point-hex-parser

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
w

@webassemblyjs/floating-point-hex-parser

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

1.14.1
latest
100

Supply Chain Security

100

Vulnerability

74

Quality

80

Maintenance

100

License

Version published
Weekly downloads
26M
-4.15%
Maintainers
1
Weekly downloads
 
Created
Issues
82

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):

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

FAQs

Package last updated on 06 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts