{"version":3,"file":"ieee754.mjs","names":[],"sources":["../../../../src/aggregator/exponential-histogram/mapping/ieee754.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * The functions and constants in this file allow us to interact\n * with the internal representation of an IEEE 64-bit floating point\n * number. We need to work with all 64-bits, thus, care needs to be\n * taken when working with Javascript's bitwise operators (<<, >>, &,\n * |, etc) as they truncate operands to 32-bits. In order to work around\n * this we work with the 64-bits as two 32-bit halves and perform bitwise\n * operations on each half independently.\n */\n\n/**\n * EXPONENT_MASK is set to 1 for the hi 32-bits of an IEEE 754\n * floating point exponent: 0x7ff00000.\n */\nconst EXPONENT_MASK = 0x7ff00000;\n\n/**\n * SIGNIFICAND_MASK is the mask for the significand portion of the hi 32-bits\n * of an IEEE 754 double-precision floating-point value: 0xfffff\n */\nconst SIGNIFICAND_MASK = 0xfffff;\n\n/**\n * EXPONENT_BIAS is the exponent bias specified for encoding\n * the IEEE 754 double-precision floating point exponent: 1023\n */\nconst EXPONENT_BIAS = 1023;\n\n/**\n * MIN_NORMAL_EXPONENT is the minimum exponent of a normalized\n * floating point: -1022.\n */\nexport const MIN_NORMAL_EXPONENT = -EXPONENT_BIAS + 1;\n\n/**\n * MAX_NORMAL_EXPONENT is the maximum exponent of a normalized\n * floating point: 1023.\n */\nexport const MAX_NORMAL_EXPONENT = EXPONENT_BIAS;\n\n/**\n * MIN_VALUE is the smallest normal number\n */\nexport const MIN_VALUE = Math.pow(2, -1022);\n\n// A single DataView, allocated once and reused. Sharing the buffer is safe\n// because every read below is synchronous.\nconst dv = new DataView(new ArrayBuffer(8));\n\n/**\n * floatBits writes value into the shared buffer and returns its two 32-bit\n * halves.\n * @param {number} value - the floating point number to read\n * @returns {{hi: number, lo: number}} the high and low 32-bit halves\n */\nfunction floatBits(value: number): { hi: number; lo: number } {\n  dv.setFloat64(0, value);\n  return { hi: dv.getUint32(0), lo: dv.getUint32(4) };\n}\n\n/**\n * getNormalBase2 extracts the normalized base-2 fractional exponent.\n * This returns k for the equation f x 2**k where f is\n * in the range [1, 2).  Note that this function is not called for\n * subnormal numbers.\n * @param {number} value - the value to determine normalized base-2 fractional\n *    exponent for\n * @returns {number} the normalized base-2 exponent\n */\nexport function getNormalBase2(value: number): number {\n  const { hi } = floatBits(value);\n  return ((hi & EXPONENT_MASK) >> 20) - EXPONENT_BIAS;\n}\n\n/**\n * isPowerOfTwo reports whether value is an exact power of two, e.g. its 52-bit\n * significand is all zeros. Only valid for positive, finite values.\n * @param {number} value - the floating point number to test\n * @returns {boolean} true if value is an exact power of two\n */\nexport function isPowerOfTwo(value: number): boolean {\n  const { hi, lo } = floatBits(value);\n  return (hi & SIGNIFICAND_MASK) === 0 && lo === 0;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAM,gBAAgB;;;;;AAMtB,MAAM,mBAAmB;;;;;AAMzB,MAAM,gBAAgB;;;;;AAMtB,MAAa,sBAAsB;;;;;AAMnC,MAAa,sBAAsB;;;;AAKnC,MAAa,YAAY,KAAK,IAAI,GAAG,KAAK;AAI1C,MAAM,qBAAK,IAAI,yBAAS,IAAI,YAAY,CAAC,CAAC;;;;;;;AAQ1C,SAAS,UAAU,OAA2C;CAC5D,GAAG,WAAW,GAAG,KAAK;CACtB,OAAO;EAAE,IAAI,GAAG,UAAU,CAAC;EAAG,IAAI,GAAG,UAAU,CAAC;CAAE;AACpD;;;;;;;;;;AAWA,SAAgB,eAAe,OAAuB;CACpD,MAAM,EAAE,OAAO,UAAU,KAAK;CAC9B,SAAS,KAAK,kBAAkB,MAAM;AACxC;;;;;;;AAQA,SAAgB,aAAa,OAAwB;CACnD,MAAM,EAAE,IAAI,OAAO,UAAU,KAAK;CAClC,QAAQ,KAAK,sBAAsB,KAAK,OAAO;AACjD"}