summaryrefslogtreecommitdiffstats
path: root/node_modules/@webassemblyjs/floating-point-hex-parser
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
commite06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch)
tree55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/@webassemblyjs/floating-point-hex-parser
downloadwebsite_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip
api, login, auth
Diffstat (limited to 'node_modules/@webassemblyjs/floating-point-hex-parser')
-rw-r--r--node_modules/@webassemblyjs/floating-point-hex-parser/LICENSE21
-rw-r--r--node_modules/@webassemblyjs/floating-point-hex-parser/README.md34
-rw-r--r--node_modules/@webassemblyjs/floating-point-hex-parser/esm/index.js42
-rw-r--r--node_modules/@webassemblyjs/floating-point-hex-parser/lib/index.js49
-rw-r--r--node_modules/@webassemblyjs/floating-point-hex-parser/package.json56
5 files changed, 202 insertions, 0 deletions
diff --git a/node_modules/@webassemblyjs/floating-point-hex-parser/LICENSE b/node_modules/@webassemblyjs/floating-point-hex-parser/LICENSE
new file mode 100644
index 0000000..d5471f8
--- /dev/null
+++ b/node_modules/@webassemblyjs/floating-point-hex-parser/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017 Mauro Bringolf
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE. \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/floating-point-hex-parser/README.md b/node_modules/@webassemblyjs/floating-point-hex-parser/README.md
new file mode 100644
index 0000000..648e09b
--- /dev/null
+++ b/node_modules/@webassemblyjs/floating-point-hex-parser/README.md
@@ -0,0 +1,34 @@
+# 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)
diff --git a/node_modules/@webassemblyjs/floating-point-hex-parser/esm/index.js b/node_modules/@webassemblyjs/floating-point-hex-parser/esm/index.js
new file mode 100644
index 0000000..d8d858d
--- /dev/null
+++ b/node_modules/@webassemblyjs/floating-point-hex-parser/esm/index.js
@@ -0,0 +1,42 @@
+export default function parse(input) {
+ input = input.toUpperCase();
+ var splitIndex = input.indexOf("P");
+ var mantissa, exponent;
+
+ if (splitIndex !== -1) {
+ mantissa = input.substring(0, splitIndex);
+ exponent = parseInt(input.substring(splitIndex + 1));
+ } else {
+ mantissa = input;
+ exponent = 0;
+ }
+
+ var dotIndex = mantissa.indexOf(".");
+
+ if (dotIndex !== -1) {
+ var integerPart = parseInt(mantissa.substring(0, dotIndex), 16);
+ var sign = Math.sign(integerPart);
+ integerPart = sign * integerPart;
+ var fractionLength = mantissa.length - dotIndex - 1;
+ var fractionalPart = parseInt(mantissa.substring(dotIndex + 1), 16);
+ var fraction = fractionLength > 0 ? fractionalPart / Math.pow(16, fractionLength) : 0;
+
+ if (sign === 0) {
+ if (fraction === 0) {
+ mantissa = sign;
+ } else {
+ if (Object.is(sign, -0)) {
+ mantissa = -fraction;
+ } else {
+ mantissa = fraction;
+ }
+ }
+ } else {
+ mantissa = sign * (integerPart + fraction);
+ }
+ } else {
+ mantissa = parseInt(mantissa, 16);
+ }
+
+ return mantissa * (splitIndex !== -1 ? Math.pow(2, exponent) : 1);
+} \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/floating-point-hex-parser/lib/index.js b/node_modules/@webassemblyjs/floating-point-hex-parser/lib/index.js
new file mode 100644
index 0000000..a867699
--- /dev/null
+++ b/node_modules/@webassemblyjs/floating-point-hex-parser/lib/index.js
@@ -0,0 +1,49 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = parse;
+
+function parse(input) {
+ input = input.toUpperCase();
+ var splitIndex = input.indexOf("P");
+ var mantissa, exponent;
+
+ if (splitIndex !== -1) {
+ mantissa = input.substring(0, splitIndex);
+ exponent = parseInt(input.substring(splitIndex + 1));
+ } else {
+ mantissa = input;
+ exponent = 0;
+ }
+
+ var dotIndex = mantissa.indexOf(".");
+
+ if (dotIndex !== -1) {
+ var integerPart = parseInt(mantissa.substring(0, dotIndex), 16);
+ var sign = Math.sign(integerPart);
+ integerPart = sign * integerPart;
+ var fractionLength = mantissa.length - dotIndex - 1;
+ var fractionalPart = parseInt(mantissa.substring(dotIndex + 1), 16);
+ var fraction = fractionLength > 0 ? fractionalPart / Math.pow(16, fractionLength) : 0;
+
+ if (sign === 0) {
+ if (fraction === 0) {
+ mantissa = sign;
+ } else {
+ if (Object.is(sign, -0)) {
+ mantissa = -fraction;
+ } else {
+ mantissa = fraction;
+ }
+ }
+ } else {
+ mantissa = sign * (integerPart + fraction);
+ }
+ } else {
+ mantissa = parseInt(mantissa, 16);
+ }
+
+ return mantissa * (splitIndex !== -1 ? Math.pow(2, exponent) : 1);
+} \ No newline at end of file
diff --git a/node_modules/@webassemblyjs/floating-point-hex-parser/package.json b/node_modules/@webassemblyjs/floating-point-hex-parser/package.json
new file mode 100644
index 0000000..424abcd
--- /dev/null
+++ b/node_modules/@webassemblyjs/floating-point-hex-parser/package.json
@@ -0,0 +1,56 @@
+{
+ "_from": "@webassemblyjs/floating-point-hex-parser@1.9.0",
+ "_id": "@webassemblyjs/floating-point-hex-parser@1.9.0",
+ "_inBundle": false,
+ "_integrity": "sha512-TG5qcFsS8QB4g4MhrxK5TqfdNe7Ey/7YL/xN+36rRjl/BlGE/NcBvJcqsRgCP6Z92mRE+7N50pRIi8SmKUbcQA==",
+ "_location": "/@webassemblyjs/floating-point-hex-parser",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "version",
+ "registry": true,
+ "raw": "@webassemblyjs/floating-point-hex-parser@1.9.0",
+ "name": "@webassemblyjs/floating-point-hex-parser",
+ "escapedName": "@webassemblyjs%2ffloating-point-hex-parser",
+ "scope": "@webassemblyjs",
+ "rawSpec": "1.9.0",
+ "saveSpec": null,
+ "fetchSpec": "1.9.0"
+ },
+ "_requiredBy": [
+ "/@webassemblyjs/wast-parser"
+ ],
+ "_resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.9.0.tgz",
+ "_shasum": "3c3d3b271bddfc84deb00f71344438311d52ffb4",
+ "_spec": "@webassemblyjs/floating-point-hex-parser@1.9.0",
+ "_where": "/home/pruss/Dev/3-minute-website/node_modules/@webassemblyjs/wast-parser",
+ "author": {
+ "name": "Mauro Bringolf"
+ },
+ "bugs": {
+ "url": "https://github.com/xtuc/webassemblyjs/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "A function to parse floating point hexadecimal strings as defined by the WebAssembly specification",
+ "gitHead": "0440b420888c1f7701eb9762ec657775506b87d8",
+ "homepage": "https://github.com/xtuc/webassemblyjs#readme",
+ "keywords": [
+ "webassembly",
+ "floating-point"
+ ],
+ "license": "MIT",
+ "main": "lib/index.js",
+ "module": "esm/index.js",
+ "name": "@webassemblyjs/floating-point-hex-parser",
+ "publishConfig": {
+ "access": "public"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/xtuc/webassemblyjs.git"
+ },
+ "scripts": {
+ "build-fuzzer": "[ -f ./test/fuzzing/parse.out ] || gcc ./test/fuzzing/parse.c -o ./test/fuzzing/parse.out -lm -Wall"
+ },
+ "version": "1.9.0"
+}