source: trip-planner-front/node_modules/@xtuc/ieee754/dist/index.cjs.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.read = read;
7exports.write = write;
8
9function read(buffer, offset, isLE, mLen, nBytes) {
10 var e, m;
11 var eLen = nBytes * 8 - mLen - 1;
12 var eMax = (1 << eLen) - 1;
13 var eBias = eMax >> 1;
14 var nBits = -7;
15 var i = isLE ? nBytes - 1 : 0;
16 var d = isLE ? -1 : 1;
17 var s = buffer[offset + i];
18 i += d;
19 e = s & (1 << -nBits) - 1;
20 s >>= -nBits;
21 nBits += eLen;
22
23 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
24
25 m = e & (1 << -nBits) - 1;
26 e >>= -nBits;
27 nBits += mLen;
28
29 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
30
31 if (e === 0) {
32 e = 1 - eBias;
33 } else if (e === eMax) {
34 return m ? NaN : (s ? -1 : 1) * Infinity;
35 } else {
36 m = m + Math.pow(2, mLen);
37 e = e - eBias;
38 }
39
40 return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
41}
42
43function write(buffer, value, offset, isLE, mLen, nBytes) {
44 var e, m, c;
45 var eLen = nBytes * 8 - mLen - 1;
46 var eMax = (1 << eLen) - 1;
47 var eBias = eMax >> 1;
48 var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
49 var i = isLE ? 0 : nBytes - 1;
50 var d = isLE ? 1 : -1;
51 var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
52 value = Math.abs(value);
53
54 if (isNaN(value) || value === Infinity) {
55 m = isNaN(value) ? 1 : 0;
56 e = eMax;
57 } else {
58 e = Math.floor(Math.log(value) / Math.LN2);
59
60 if (value * (c = Math.pow(2, -e)) < 1) {
61 e--;
62 c *= 2;
63 }
64
65 if (e + eBias >= 1) {
66 value += rt / c;
67 } else {
68 value += rt * Math.pow(2, 1 - eBias);
69 }
70
71 if (value * c >= 2) {
72 e++;
73 c /= 2;
74 }
75
76 if (e + eBias >= eMax) {
77 m = 0;
78 e = eMax;
79 } else if (e + eBias >= 1) {
80 m = (value * c - 1) * Math.pow(2, mLen);
81 e = e + eBias;
82 } else {
83 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
84 e = 0;
85 }
86 }
87
88 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
89
90 e = e << mLen | m;
91 eLen += mLen;
92
93 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
94
95 buffer[offset + i - d] |= s * 128;
96}
Note: See TracBrowser for help on using the repository browser.