source: imaps-frontend/node_modules/@webassemblyjs/helper-numbers/lib/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[79a0317]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 _long2 = _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 // $FlowIgnore
84 var _long;
85
86 if (isHexLiteral(sourceString)) {
87 _long = _long2["default"].fromString(sourceString, false, 16);
88 } else if (isDecimalExponentLiteral(sourceString)) {
89 throw new Error("This number literal format is yet to be implemented.");
90 } else {
91 _long = _long2["default"].fromString(sourceString);
92 }
93
94 return {
95 high: _long.high,
96 low: _long.low
97 };
98}
99
100var NAN_WORD = /^\+?-?nan/;
101var INF_WORD = /^\+?-?inf/;
102
103function isInfLiteral(sourceString) {
104 return INF_WORD.test(sourceString.toLowerCase());
105}
106
107function isNanLiteral(sourceString) {
108 return NAN_WORD.test(sourceString.toLowerCase());
109}
110
111function isDecimalExponentLiteral(sourceString) {
112 return !isHexLiteral(sourceString) && sourceString.toUpperCase().includes("E");
113}
114
115function isHexLiteral(sourceString) {
116 return sourceString.substring(0, 2).toUpperCase() === "0X" || sourceString.substring(0, 3).toUpperCase() === "-0X";
117}
Note: See TracBrowser for help on using the repository browser.