Socket
Socket
Sign inDemoInstall

@petamoriken/float16

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@petamoriken/float16 - npm Package Compare versions

Comparing version 3.4.11 to 3.4.12

359

browser/float16.js

@@ -1,2 +0,2 @@

/*! @petamoriken/float16 v3.4.11 | MIT License - https://git.io/float16 */
/*! @petamoriken/float16 v3.4.12 | MIT License - https://git.io/float16 */

@@ -183,4 +183,4 @@ const float16 = (function (exports) {

/**
* @param {Iterator<number>} iterator
* @returns {IterableIterator<number>}
* @param {Iterator<T>} iterator
* @returns {IterableIterator<T>}
*/

@@ -230,2 +230,11 @@ function wrapInArrayIterator(iterator) {

* @param {unknown} value
* @returns {value is BigInt64Array|BigUint64Array}
*/
function isBigIntTypedArray(value) {
const typedArrayName = getTypedArrayPrototypeSymbolToStringTag.call(value);
return typedArrayName === "BigInt64Array" || typedArrayName === "BigUint64Array";
}
/**
* @param {unknown} value
* @returns {value is DataView}

@@ -487,3 +496,3 @@ */

* @param {unknown} target
* @returns {boolean}
* @returns {target is Float16Array}
*/

@@ -496,3 +505,3 @@ function isFloat16Array(target) {

* @param {unknown} target
* @returns {boolean}
* @returns {target is Uint16Array & { __float16bits: never }}
*/

@@ -507,4 +516,4 @@ function isFloat16BitsArray(target) {

*/
function assertFloat16BitsArray(target) {
if (!isFloat16BitsArray(target)) {
function assertFloat16Array(target) {
if (!isFloat16Array(target)) {
throw new TypeError("This is not a Float16Array");

@@ -515,6 +524,24 @@ }

/**
* @param {unknown} target
* @throws {TypeError}
*/
function assertSpeciesTypedArray(target) {
if (isFloat16Array(target)) {
return;
}
if (!isTypedArray(target)) {
throw new TypeError("This is not a TypedArray");
}
if (isBigIntTypedArray(target)) {
throw new TypeError("Cannot mix BigInt and other types, use explicit conversions");
}
}
/**
* @param {Float16Array} float16
* @returns {ArrayLike<number>}
* @returns {Uint16Array & { __float16bits: never }}
*/
function getFloat16BitsArrayFromFloat16Array(float16) {
function getFloat16BitsArray(float16) {
let target = _(float16).target;

@@ -532,3 +559,3 @@

/**
* @param {ArrayLike<number>} float16bitsArray
* @param {Uint16Array & { __float16bits: never }} float16bitsArray
* @returns {number[]}

@@ -547,28 +574,15 @@ */

const defaultFloat16ArrayMethods = new WeakSet();
const TypedArrayPrototype = Reflect.getPrototypeOf(Uint8Array).prototype;
/**
* @param {unknown} target
* @returns {boolean}
*/
function isDefaultFloat16ArrayMethods(target) {
return typeof target === "function" && defaultFloat16ArrayMethods.has(target);
const TypedArrayPrototypeGetters = new Set();
for (const key of Reflect.ownKeys(TypedArrayPrototype)) {
const descriptor = Object.getOwnPropertyDescriptor(TypedArrayPrototype, key);
if (hasOwn(descriptor, "get")) {
TypedArrayPrototypeGetters.add(key);
}
}
/** @type {ProxyHandler<Function>} */
const applyHandler = Object.freeze({
apply(func, thisArg, args) {
// peel off Proxy
if (isFloat16Array(thisArg)) {
const target = getFloat16BitsArrayFromFloat16Array(thisArg);
return Reflect.apply(func, target, args);
}
return Reflect.apply(func, thisArg, args);
},
});
/** @type {ProxyHandler<Float16Array>} */
const handler = Object.freeze({
get(target, key) {
get(target, key, receiver) {
if (isCanonicalIntegerIndexString(key) && hasOwn(target, key)) {

@@ -578,18 +592,10 @@ return convertToNumber(Reflect.get(target, key));

const ret = Reflect.get(target, key);
if (!isDefaultFloat16ArrayMethods(ret)) {
return ret;
if (TypedArrayPrototypeGetters.has(key)) {
return Reflect.get(target, key);
}
// TypedArray methods can't be called by Proxy Object
let proxy = _(ret).proxy;
if (proxy === undefined) {
proxy = _(ret).proxy = new Proxy(ret, applyHandler);
}
return proxy;
return Reflect.get(target, key, receiver);
},
set(target, key, value) {
set(target, key, value, receiver) {
if (isCanonicalIntegerIndexString(key) && hasOwn(target, key)) {

@@ -599,3 +605,3 @@ return Reflect.set(target, key, roundToFloat16Bits(value));

return Reflect.set(target, key, value);
return Reflect.set(target, key, value, receiver);
},

@@ -612,3 +618,3 @@ });

// peel off Proxy
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(input);
const float16bitsArray = getFloat16BitsArray(input);
super(float16bitsArray);

@@ -625,2 +631,6 @@

if (isTypedArray(input)) {
if (isBigIntTypedArray(input)) {
throw new TypeError("Cannot mix BigInt and other types, use explicit conversions");
}
list = input;

@@ -691,5 +701,2 @@ length = input.length;

// this private storage
_(this).proxy = proxy;
return proxy;

@@ -786,3 +793,3 @@ }

const proxy = new Float16Array(length);
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(proxy);
const float16bitsArray = getFloat16BitsArray(proxy);

@@ -807,5 +814,5 @@ for (let i = 0; i < length; ++i) {

keys() {
assertFloat16BitsArray(this);
assertFloat16Array(this);
return super.keys();
return Reflect.apply(super.keys, getFloat16BitsArray(this), []);
}

@@ -819,5 +826,5 @@

values() {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const arrayIterator = super.values();
const arrayIterator = Reflect.apply(super.values, getFloat16BitsArray(this), []);
return wrapInArrayIterator((function* () {

@@ -836,5 +843,5 @@ for (const val of arrayIterator) {

entries() {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const arrayIterator = super.entries();
const arrayIterator = Reflect.apply(super.entries, getFloat16BitsArray(this), []);
return wrapInArrayIterator((function* () {

@@ -849,5 +856,7 @@ for (const [i, val] of arrayIterator) {

at(index) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const relativeIndex = ToIntegerOrInfinity(index);

@@ -860,3 +869,3 @@ const k = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;

return convertToNumber(this[k]);
return convertToNumber(float16bitsArray[k]);
}

@@ -866,8 +875,10 @@

map(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];
const Constructor = SpeciesConstructor(this, Float16Array);
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);

@@ -877,7 +888,7 @@ // for optimization

const proxy = new Float16Array(length);
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(proxy);
const array = getFloat16BitsArray(proxy);
for (let i = 0; i < length; ++i) {
const val = convertToNumber(this[i]);
float16bitsArray[i] = roundToFloat16Bits(callback.call(thisArg, val, i, _(this).proxy));
const val = convertToNumber(float16bitsArray[i]);
array[i] = roundToFloat16Bits(callback.call(thisArg, val, i, this));
}

@@ -889,6 +900,7 @@

const array = new Constructor(length);
assertSpeciesTypedArray(array);
for (let i = 0; i < length; ++i) {
const val = convertToNumber(this[i]);
array[i] = callback.call(thisArg, val, i, _(this).proxy);
const val = convertToNumber(float16bitsArray[i]);
array[i] = callback.call(thisArg, val, i, this);
}

@@ -901,5 +913,7 @@

filter(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];

@@ -909,4 +923,4 @@

for (let i = 0; i < length; ++i) {
const val = convertToNumber(this[i]);
if (callback.call(thisArg, val, i, _(this).proxy)) {
const val = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, val, i, this)) {
kept.push(val);

@@ -916,4 +930,5 @@ }

const Constructor = SpeciesConstructor(this, Float16Array);
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
const array = new Constructor(kept);
assertSpeciesTypedArray(array);

@@ -925,5 +940,7 @@ return array;

reduce(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
if (length === 0 && opts.length === 0) {

@@ -935,3 +952,3 @@ throw TypeError("Reduce of empty array with no initial value");

if (opts.length === 0) {
accumulator = convertToNumber(this[0]);
accumulator = convertToNumber(float16bitsArray[0]);
start = 1;

@@ -944,3 +961,3 @@ } else {

for (let i = start; i < length; ++i) {
accumulator = callback(accumulator, convertToNumber(this[i]), i, _(this).proxy);
accumulator = callback(accumulator, convertToNumber(float16bitsArray[i]), i, this);
}

@@ -953,5 +970,7 @@

reduceRight(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
if (length === 0 && opts.length === 0) {

@@ -963,3 +982,3 @@ throw TypeError("Reduce of empty array with no initial value");

if (opts.length === 0) {
accumulator = convertToNumber(this[length - 1]);
accumulator = convertToNumber(float16bitsArray[length - 1]);
start = length - 2;

@@ -972,3 +991,3 @@ } else {

for (let i = start; i >= 0; --i) {
accumulator = callback(accumulator, convertToNumber(this[i]), i, _(this).proxy);
accumulator = callback(accumulator, convertToNumber(float16bitsArray[i]), i, this);
}

@@ -981,9 +1000,11 @@

forEach(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
callback.call(thisArg, convertToNumber(this[i]), i, _(this).proxy);
callback.call(thisArg, convertToNumber(float16bitsArray[i]), i, this);
}

@@ -994,10 +1015,12 @@ }

find(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
const value = convertToNumber(this[i]);
if (callback.call(thisArg, value, i, _(this).proxy)) {
const value = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, value, i, this)) {
return value;

@@ -1010,10 +1033,12 @@ }

findIndex(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
const value = convertToNumber(this[i]);
if (callback.call(thisArg, value, i, _(this).proxy)) {
const value = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, value, i, this)) {
return i;

@@ -1028,10 +1053,12 @@ }

findLast(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];
for (let i = length - 1; i >= 0; --i) {
const value = convertToNumber(this[i]);
if (callback.call(thisArg, value, i, _(this).proxy)) {
const value = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, value, i, this)) {
return value;

@@ -1044,10 +1071,12 @@ }

findLastIndex(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];
for (let i = length - 1; i >= 0; --i) {
const value = convertToNumber(this[i]);
if (callback.call(thisArg, value, i, _(this).proxy)) {
const value = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, value, i, this)) {
return i;

@@ -1062,9 +1091,11 @@ }

every(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
if (!callback.call(thisArg, convertToNumber(this[i]), i, _(this).proxy)) {
if (!callback.call(thisArg, convertToNumber(float16bitsArray[i]), i, this)) {
return false;

@@ -1079,9 +1110,11 @@ }

some(callback, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
if (callback.call(thisArg, convertToNumber(this[i]), i, _(this).proxy)) {
if (callback.call(thisArg, convertToNumber(float16bitsArray[i]), i, this)) {
return true;

@@ -1096,3 +1129,3 @@ }

set(input, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);

@@ -1104,12 +1137,19 @@ const targetOffset = ToIntegerOrInfinity(opts[0]);

if (isBigIntTypedArray(input)) {
throw new TypeError("Cannot mix BigInt and other types, use explicit conversions");
}
// for optimization
if (isFloat16Array(input)) {
// peel off Proxy
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(input);
super.set(float16bitsArray, targetOffset);
return;
return Reflect.apply(super.set, getFloat16BitsArray(this), [
getFloat16BitsArray(input),
targetOffset,
]);
}
const targetLength = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const targetLength = float16bitsArray.length;
const src = Object(input);

@@ -1123,3 +1163,3 @@ const srcLength = LengthOfArrayLike(src);

for (let i = 0; i < srcLength; ++i) {
this[i + targetOffset] = roundToFloat16Bits(src[i]);
float16bitsArray[i + targetOffset] = roundToFloat16Bits(src[i]);
}

@@ -1130,7 +1170,7 @@ }

reverse() {
assertFloat16BitsArray(this);
assertFloat16Array(this);
super.reverse();
Reflect.apply(super.reverse, getFloat16BitsArray(this), []);
return _(this).proxy;
return this;
}

@@ -1140,7 +1180,7 @@

fill(value, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
super.fill(roundToFloat16Bits(value), ...opts);
Reflect.apply(super.fill, getFloat16BitsArray(this), [roundToFloat16Bits(value), ...opts]);
return _(this).proxy;
return this;
}

@@ -1150,7 +1190,7 @@

copyWithin(target, start, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
super.copyWithin(target, start, ...opts);
Reflect.apply(super.copyWithin, getFloat16BitsArray(this), [target, start, ...opts]);
return _(this).proxy;
return this;
}

@@ -1160,8 +1200,8 @@

sort(...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const compare = opts[0] !== undefined ? opts[0] : defaultCompare;
super.sort((x, y) => { return compare(convertToNumber(x), convertToNumber(y)); });
Reflect.apply(super.sort, getFloat16BitsArray(this), [(x, y) => { return compare(convertToNumber(x), convertToNumber(y)); }]);
return _(this).proxy;
return this;
}

@@ -1171,14 +1211,15 @@

slice(...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const Constructor = SpeciesConstructor(this, Float16Array);
const float16bitsArray = getFloat16BitsArray(this);
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
// for optimization
if (Constructor === Float16Array) {
const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length);
const float16bitsArray = uint16.slice(...opts);
return new Float16Array(float16bitsArray.buffer);
const uint16 = new Uint16Array(float16bitsArray.buffer, float16bitsArray.byteOffset, float16bitsArray.length);
return new Float16Array(uint16.slice(...opts).buffer);
}
const length = this.length;
const length = float16bitsArray.length;
const start = ToIntegerOrInfinity(opts[0]);

@@ -1207,2 +1248,3 @@ const end = opts[1] === undefined ? length : ToIntegerOrInfinity(opts[1]);

const array = new Constructor(count);
assertSpeciesTypedArray(array);

@@ -1215,3 +1257,3 @@ if (count === 0) {

while (k < final) {
array[n] = convertToNumber(this[k]);
array[n] = convertToNumber(float16bitsArray[k]);
++k;

@@ -1226,10 +1268,13 @@ ++n;

subarray(...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length);
const float16bitsArray = uint16.subarray(...opts);
const float16bitsArray = getFloat16BitsArray(this);
const Constructor = SpeciesConstructor(this, Float16Array);
const array = new Constructor(float16bitsArray.buffer, float16bitsArray.byteOffset, float16bitsArray.length);
const uint16 = new Uint16Array(float16bitsArray.buffer, float16bitsArray.byteOffset, float16bitsArray.length);
const subarray = uint16.subarray(...opts);
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
const array = new Constructor(subarray.buffer, subarray.byteOffset, subarray.length);
assertSpeciesTypedArray(array);
return array;

@@ -1240,6 +1285,8 @@ }

indexOf(element, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
let from = ToIntegerOrInfinity(opts[0]);

@@ -1258,3 +1305,3 @@ if (from === Infinity) {

for (let i = from; i < length; ++i) {
if (hasOwn(this, i) && convertToNumber(this[i]) === element) {
if (hasOwn(float16bitsArray, i) && convertToNumber(float16bitsArray[i]) === element) {
return i;

@@ -1269,6 +1316,8 @@ }

lastIndexOf(element, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
let from = opts.length >= 1 ? ToIntegerOrInfinity(opts[0]) : length - 1;

@@ -1286,3 +1335,3 @@ if (from === -Infinity) {

for (let i = from; i >= 0; --i) {
if (hasOwn(this, i) && convertToNumber(this[i]) === element) {
if (hasOwn(float16bitsArray, i) && convertToNumber(float16bitsArray[i]) === element) {
return i;

@@ -1297,6 +1346,8 @@ }

includes(element, ...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const length = this.length;
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
let from = ToIntegerOrInfinity(opts[0]);

@@ -1316,3 +1367,3 @@ if (from === Infinity) {

for (let i = from; i < length; ++i) {
const value = convertToNumber(this[i]);
const value = convertToNumber(float16bitsArray[i]);

@@ -1333,5 +1384,6 @@ if (isNaN && Number.isNaN(value)) {

join(...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const array = copyToArray(this);
const float16bitsArray = getFloat16BitsArray(this);
const array = copyToArray(float16bitsArray);

@@ -1343,5 +1395,6 @@ return array.join(...opts);

toLocaleString(...opts) {
assertFloat16BitsArray(this);
assertFloat16Array(this);
const array = copyToArray(this);
const float16bitsArray = getFloat16BitsArray(this);
const array = copyToArray(float16bitsArray);

@@ -1374,14 +1427,2 @@ return array.toLocaleString(...opts);

for (const key of Reflect.ownKeys(Float16ArrayPrototype)) {
// constructor is not callable
if (key === "constructor") {
continue;
}
const val = Float16ArrayPrototype[key];
if (typeof val === "function") {
defaultFloat16ArrayMethods.add(val);
}
}
/**

@@ -1388,0 +1429,0 @@ * returns an unsigned 16-bit float at the specified byte offset from the start of the DataView.

{
"name": "@petamoriken/float16",
"version": "3.4.11",
"version": "3.4.12",
"description": "half precision floating point for JavaScript",

@@ -61,3 +61,3 @@ "keywords": [

"docs:test:assets": "cp test/*.js docs/test && tools/power; cp test/browser/*.html docs/test",
"docs:test:dependencies": "cp $(npm root)/mocha/mocha.js $(npm root)/mocha/mocha.css $(npm root)/power-assert/build/power-assert.js docs/test",
"docs:test:dependencies": "cp node_modules/mocha/mocha.js node_modules/mocha/mocha.css node_modules/power-assert/build/power-assert.js docs/test",
"lint": "eslint *.js src/**/*.mjs test/**/*.js test/**/*.mjs",

@@ -77,5 +77,5 @@ "prepublishOnly": "yarn run lint && yarn test",

"babel-plugin-replace-import-extension": "^1.1.1",
"browserslist": "^4.17.3",
"eslint": "^7.4.0",
"eslint-plugin-import": "^2.20.2",
"browserslist": "^4.17.4",
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jsdoc": "^36.1.1",

@@ -93,3 +93,4 @@ "espower-cli": "^1.1.0",

"source-map-support": "^0.5.20"
}
},
"packageManager": "yarn@1.22.11"
}

@@ -1,2 +0,2 @@

# <a href="https://git.io/float16">@petamoriken/float16</a>
# <a href="https://git.io/float16">float16</a>

@@ -3,0 +3,0 @@ <p align="center">

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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