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