Files
codeql-action/node_modules/es-abstract/helpers/valueToFloat64Bytes.js
dependabot[bot] e7e35baaf0 Bump the npm group with 2 updates (#1819)
* Bump the npm group with 2 updates

Bumps the npm group with 2 updates: [eslint](https://github.com/eslint/eslint) and [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import).


Updates `eslint` from 8.45.0 to 8.46.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.45.0...v8.46.0)

Updates `eslint-plugin-import` from 2.27.5 to 2.28.0
- [Release notes](https://github.com/import-js/eslint-plugin-import/releases)
- [Changelog](https://github.com/import-js/eslint-plugin-import/blob/main/CHANGELOG.md)
- [Commits](https://github.com/import-js/eslint-plugin-import/compare/v2.27.5...v2.28.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: eslint-plugin-import
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update checked-in dependencies

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-08-01 03:35:02 -07:00

84 lines
2.9 KiB
JavaScript

'use strict';
var GetIntrinsic = require('get-intrinsic');
var $parseInt = GetIntrinsic('%parseInt%');
var $abs = GetIntrinsic('%Math.abs%');
var $floor = GetIntrinsic('%Math.floor%');
var callBound = require('call-bind/callBound');
var $strIndexOf = callBound('String.prototype.indexOf');
var $strSlice = callBound('String.prototype.slice');
var fractionToBitString = require('../helpers/fractionToBinaryString');
var intToBinString = require('../helpers/intToBinaryString');
var isNegativeZero = require('./isNegativeZero');
var float64bias = 1023;
var elevenOnes = '11111111111';
var elevenZeroes = '00000000000';
var fiftyOneZeroes = elevenZeroes + elevenZeroes + elevenZeroes + elevenZeroes + '0000000';
// IEEE 754-1985
module.exports = function valueToFloat64Bytes(value, isLittleEndian) {
var signBit = value < 0 || isNegativeZero(value) ? '1' : '0';
var exponentBits;
var significandBits;
if (isNaN(value)) {
exponentBits = elevenOnes;
significandBits = '1' + fiftyOneZeroes;
} else if (!isFinite(value)) {
exponentBits = elevenOnes;
significandBits = '0' + fiftyOneZeroes;
} else if (value === 0) {
exponentBits = elevenZeroes;
significandBits = '0' + fiftyOneZeroes;
} else {
value = $abs(value); // eslint-disable-line no-param-reassign
// Isolate the integer part (digits before the decimal):
var integerPart = $floor(value);
var intBinString = intToBinString(integerPart); // bit string for integer part
var fracBinString = fractionToBitString(value - integerPart); // bit string for fractional part
var numberOfBits;
// find exponent needed to normalize integer+fractional parts
if (intBinString) {
exponentBits = intBinString.length - 1; // move the decimal to the left
} else {
var first1 = $strIndexOf(fracBinString, '1');
if (first1 > -1) {
numberOfBits = first1 + 1;
}
exponentBits = -numberOfBits; // move the decimal to the right
}
significandBits = intBinString + fracBinString;
if (exponentBits < 0) {
// subnormals
if (exponentBits <= -float64bias) {
numberOfBits = float64bias - 1; // limit number of removed bits
}
significandBits = $strSlice(significandBits, numberOfBits); // remove all leading 0s and the first 1 for normal values; for subnormals, remove up to `float64bias - 1` leading bits
} else {
significandBits = $strSlice(significandBits, 1); // remove the leading '1' (implicit/hidden bit)
}
exponentBits = $strSlice(elevenZeroes + intToBinString(exponentBits + float64bias), -11); // Convert the exponent to a bit string
significandBits = $strSlice(significandBits + fiftyOneZeroes + '0', 0, 52); // fill in any trailing zeros and ensure we have only 52 fraction bits
}
var bits = signBit + exponentBits + significandBits;
var rawBytes = [];
for (var i = 0; i < 8; i++) {
var targetIndex = isLittleEndian ? 8 - i - 1 : i;
rawBytes[targetIndex] = $parseInt($strSlice(bits, i * 8, (i + 1) * 8), 2);
}
return rawBytes;
};