• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Test data for float encoding and decoding.
3 */
4goog.module('protobuf.binary.floatTestPairs');
5
6const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
7const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
8
9/**
10 * An array of Pairs of float values and their bit representation.
11 * This is used to test encoding and decoding from/to the protobuf wire format.
12 * @return {!Array<{name: string, floatValue:number, bufferDecoder:
13 *     !BufferDecoder}>}
14 */
15function getFloatPairs() {
16  const floatPairs = [
17    {
18      name: 'zero',
19      floatValue: 0,
20      bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x00),
21    },
22    {
23      name: 'minus zero',
24      floatValue: -0,
25      bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x80)
26    },
27    {
28      name: 'one ',
29      floatValue: 1,
30      bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0x3F)
31    },
32    {
33      name: 'minus one',
34      floatValue: -1,
35      bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0xBF)
36    },
37    {
38      name: 'two',
39      floatValue: 2,
40      bufferDecoder: createBufferDecoder(0x00, 0x00, 0x00, 0x40)
41    },
42    {
43      name: 'max float32',
44      floatValue: Math.pow(2, 127) * (2 - 1 / Math.pow(2, 23)),
45      bufferDecoder: createBufferDecoder(0xFF, 0xFF, 0x7F, 0x7F)
46    },
47
48    {
49      name: 'min float32',
50      floatValue: 1 / Math.pow(2, 127 - 1),
51      bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0x00)
52    },
53
54    {
55      name: 'Infinity',
56      floatValue: Infinity,
57      bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0x7F)
58    },
59    {
60      name: 'minus Infinity',
61      floatValue: -Infinity,
62      bufferDecoder: createBufferDecoder(0x00, 0x00, 0x80, 0xFF)
63    },
64    {
65      name: '1.5',
66      floatValue: 1.5,
67      bufferDecoder: createBufferDecoder(0x00, 0x00, 0xC0, 0x3F)
68    },
69    {
70      name: '1.6',
71      floatValue: 1.6,
72      bufferDecoder: createBufferDecoder(0xCD, 0xCC, 0xCC, 0x3F)
73    },
74  ];
75  return [...floatPairs];
76}
77
78exports = {getFloatPairs};
79