source: trip-planner-front/node_modules/@webassemblyjs/helper-numbers/lib/index.js@ 59329aa

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

initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.parse32F = parse32F;
7exports.parse64F = parse64F;
8exports.parse32I = parse32I;
9exports.parseU32 = parseU32;
10exports.parse64I = parse64I;
11exports.isInfLiteral = isInfLiteral;
12exports.isNanLiteral = isNanLiteral;
13
14var _long = _interopRequireDefault(require("@xtuc/long"));
15
16var _floatingPointHexParser = _interopRequireDefault(require("@webassemblyjs/floating-point-hex-parser"));
17
18var _helperApiError = require("@webassemblyjs/helper-api-error");
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22function parse32F(sourceString) {
23 if (isHexLiteral(sourceString)) {
24 return (0, _floatingPointHexParser.default)(sourceString);
25 }
26
27 if (isInfLiteral(sourceString)) {
28 return sourceString[0] === "-" ? -1 : 1;
29 }
30
31 if (isNanLiteral(sourceString)) {
32 return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x400000);
33 }
34
35 return parseFloat(sourceString);
36}
37
38function parse64F(sourceString) {
39 if (isHexLiteral(sourceString)) {
40 return (0, _floatingPointHexParser.default)(sourceString);
41 }
42
43 if (isInfLiteral(sourceString)) {
44 return sourceString[0] === "-" ? -1 : 1;
45 }
46
47 if (isNanLiteral(sourceString)) {
48 return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x8000000000000);
49 }
50
51 if (isHexLiteral(sourceString)) {
52 return (0, _floatingPointHexParser.default)(sourceString);
53 }
54
55 return parseFloat(sourceString);
56}
57
58function parse32I(sourceString) {
59 var value = 0;
60
61 if (isHexLiteral(sourceString)) {
62 value = ~~parseInt(sourceString, 16);
63 } else if (isDecimalExponentLiteral(sourceString)) {
64 throw new Error("This number literal format is yet to be implemented.");
65 } else {
66 value = parseInt(sourceString, 10);
67 }
68
69 return value;
70}
71
72function parseU32(sourceString) {
73 var value = parse32I(sourceString);
74
75 if (value < 0) {
76 throw new _helperApiError.CompileError("Illegal value for u32: " + sourceString);
77 }
78
79 return value;
80}
81
82function parse64I(sourceString) {
83 var long;
84
85 if (isHexLiteral(sourceString)) {
86 long = _long.default.fromString(sourceString, false, 16);
87 } else if (isDecimalExponentLiteral(sourceString)) {
88 throw new Error("This number literal format is yet to be implemented.");
89 } else {
90 long = _long.default.fromString(sourceString);
91 }
92
93 return {
94 high: long.high,
95 low: long.low
96 };
97}
98
99var NAN_WORD = /^\+?-?nan/;
100var INF_WORD = /^\+?-?inf/;
101
102function isInfLiteral(sourceString) {
103 return INF_WORD.test(sourceString.toLowerCase());
104}
105
106function isNanLiteral(sourceString) {
107 return NAN_WORD.test(sourceString.toLowerCase());
108}
109
110function isDecimalExponentLiteral(sourceString) {
111 return !isHexLiteral(sourceString) && sourceString.toUpperCase().includes("E");
112}
113
114function isHexLiteral(sourceString) {
115 return sourceString.substring(0, 2).toUpperCase() === "0X" || sourceString.substring(0, 3).toUpperCase() === "-0X";
116}
Note: See TracBrowser for help on using the repository browser.