New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

big-float-wasm

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

big-float-wasm - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

78

bf.js

@@ -224,2 +224,77 @@ const { camelize } = require("humps");

toIEEE754Hex(opts) {
const { prec, expnBits } = normalizeOptionsObject(opts);
const biasedExpnLimit = Math.pow(2, expnBits);
const signBit = this.sign ? 1 : 0;
let skipFirstFracBit = true;
let extraFracZeroes = 0;
let biasedExpn;
if (this.expn === bf.expnZero) biasedExpn = 0;
else if (this.expn === bf.expnInf || this.expn === bf.expnNaN)
biasedExpn = biasedExpnLimit - 1;
else {
const expnBias = Math.pow(2, expnBits - 1) - 2;
biasedExpn = this.expn + expnBias;
if (biasedExpn <= 0 && biasedExpn > 1 - prec) {
extraFracZeroes = -biasedExpn;
skipFirstFracBit = false;
biasedExpn = 0;
} else if (biasedExpn >= biasedExpnLimit)
throw new Error(
`can't represent ${this.toString()} as IEEE 754 given precision ${prec} and ${expnBits} exponent bits`
);
}
const resBuf = new ArrayBuffer(Math.ceil((prec + expnBits) / 8));
const resView = new DataView(resBuf);
const resHeader = ((signBit << expnBits) | biasedExpn) << (31 - expnBits);
resView.setInt32(0, resHeader);
const fracStart = Math.floor((expnBits + 1 + extraFracZeroes) / 8);
const fracStartOffset = (expnBits + 1 + extraFracZeroes) % 8;
if (this.expn === bf.expnNaN) {
resView.setUint8(
fracStart,
resView.getUint8(fracStart) | (0x80 >>> fracStartOffset)
);
} else if (this.tab != null) {
const tabBytes = new Uint8Array(
this.tab.buffer,
this.tab.byteOffset,
this.tab.byteLength
);
const byteOffset = skipFirstFracBit
? fracStartOffset - 1
: fracStartOffset;
const byteMask = (1 << byteOffset) - 1;
resView.setUint8(
fracStart,
resView.getUint8(fracStart) |
((tabBytes[tabBytes.length - 1] &
(skipFirstFracBit ? 0x7f : 0xff)) >>>
byteOffset)
);
for (
let i = 1;
i < tabBytes.length && fracStart + i < resView.byteLength;
i++
) {
resView.setUint8(
fracStart + i,
((tabBytes[tabBytes.length - i] & byteMask) << (8 - byteOffset)) |
(tabBytes[tabBytes.length - i - 1] >>> byteOffset)
);
}
}
return (
"0x" +
Array.from(new Uint8Array(resBuf))
.map(b => b.toString(16).padStart(2, "0"))
.join("")
);
}
[inspectCustom](depth, options) {

@@ -240,2 +315,5 @@ return `${options.stylize("bf", "name")}(${options.stylize(

bf.expnBitsMax = wordSize * 8 - 2;
bf.expnZero = -Math.pow(2, wordSize * 8 - 1);
bf.expnInf = Math.pow(2, wordSize * 8 - 1) - 2;
bf.expnNaN = Math.pow(2, wordSize * 8 - 1) - 1;
bf.precMin = 2;

@@ -242,0 +320,0 @@ bf.precMax = Math.pow(2, bf.expnBitsMax) - 2;

4

package.json
{
"name": "big-float-wasm",
"version": "1.0.0",
"version": "1.1.0",
"description": "Big floats via WASM",

@@ -10,3 +10,3 @@ "main": "index.js",

"author": "",
"license": "ISC",
"license": "MIT",
"devDependencies": {},

@@ -13,0 +13,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc