1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.encodeF32 = encodeF32;
|
---|
7 | exports.encodeF64 = encodeF64;
|
---|
8 | exports.decodeF32 = decodeF32;
|
---|
9 | exports.decodeF64 = decodeF64;
|
---|
10 | exports.DOUBLE_PRECISION_MANTISSA = exports.SINGLE_PRECISION_MANTISSA = exports.NUMBER_OF_BYTE_F64 = exports.NUMBER_OF_BYTE_F32 = void 0;
|
---|
11 |
|
---|
12 | var _ieee = require("@xtuc/ieee754");
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * According to https://webassembly.github.io/spec/binary/values.html#binary-float
|
---|
16 | * n = 32/8
|
---|
17 | */
|
---|
18 | var NUMBER_OF_BYTE_F32 = 4;
|
---|
19 | /**
|
---|
20 | * According to https://webassembly.github.io/spec/binary/values.html#binary-float
|
---|
21 | * n = 64/8
|
---|
22 | */
|
---|
23 |
|
---|
24 | exports.NUMBER_OF_BYTE_F32 = NUMBER_OF_BYTE_F32;
|
---|
25 | var NUMBER_OF_BYTE_F64 = 8;
|
---|
26 | exports.NUMBER_OF_BYTE_F64 = NUMBER_OF_BYTE_F64;
|
---|
27 | var SINGLE_PRECISION_MANTISSA = 23;
|
---|
28 | exports.SINGLE_PRECISION_MANTISSA = SINGLE_PRECISION_MANTISSA;
|
---|
29 | var DOUBLE_PRECISION_MANTISSA = 52;
|
---|
30 | exports.DOUBLE_PRECISION_MANTISSA = DOUBLE_PRECISION_MANTISSA;
|
---|
31 |
|
---|
32 | function encodeF32(v) {
|
---|
33 | var buffer = [];
|
---|
34 | (0, _ieee.write)(buffer, v, 0, true, SINGLE_PRECISION_MANTISSA, NUMBER_OF_BYTE_F32);
|
---|
35 | return buffer;
|
---|
36 | }
|
---|
37 |
|
---|
38 | function encodeF64(v) {
|
---|
39 | var buffer = [];
|
---|
40 | (0, _ieee.write)(buffer, v, 0, true, DOUBLE_PRECISION_MANTISSA, NUMBER_OF_BYTE_F64);
|
---|
41 | return buffer;
|
---|
42 | }
|
---|
43 |
|
---|
44 | function decodeF32(bytes) {
|
---|
45 | var buffer = Buffer.from(bytes);
|
---|
46 | return (0, _ieee.read)(buffer, 0, true, SINGLE_PRECISION_MANTISSA, NUMBER_OF_BYTE_F32);
|
---|
47 | }
|
---|
48 |
|
---|
49 | function decodeF64(bytes) {
|
---|
50 | var buffer = Buffer.from(bytes);
|
---|
51 | return (0, _ieee.read)(buffer, 0, true, DOUBLE_PRECISION_MANTISSA, NUMBER_OF_BYTE_F64);
|
---|
52 | } |
---|