Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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.3.2 to 3.3.3

128

browser/float16.js

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

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

@@ -274,3 +274,3 @@ var float16 = (function (exports) {

function defaultCompareFunction(x, y) {
function defaultCompare(x, y) {
const [isNaN_x, isNaN_y] = [Number.isNaN(x), Number.isNaN(y)];

@@ -313,3 +313,2 @@

const toString = Object.prototype.toString;
/**

@@ -331,2 +330,4 @@ * @param {unknown} value

}
const toString = Object.prototype.toString;
/**

@@ -337,7 +338,8 @@ * @param {unknown} value

function isDataView(value) {
return ArrayBuffer.isView(value) && toString.call(value) === "[object DataView]";
}
const typedArrayTags = new Set(["[object Float32Array]", "[object Float64Array]", "[object Int8Array]", "[object Int16Array]", "[object Int32Array]", "[object Uint8Array]", "[object Uint8ClampedArray]", "[object Uint16Array]", "[object Uint32Array]", "[object BigInt64Array]", "[object BigUint64Array]"]);
} // Inspired by util.types implementation of Node.js
const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array).prototype;
const getTypedArrayPrototypeSybolToStringTag = Object.getOwnPropertyDescriptor(TypedArrayPrototype, Symbol.toStringTag).get;
/**

@@ -349,3 +351,3 @@ * @param {unknown} value

function isTypedArray(value) {
return ArrayBuffer.isView(value) && typedArrayTags.has(toString.call(value));
return getTypedArrayPrototypeSybolToStringTag.call(value) !== undefined;
}

@@ -401,3 +403,3 @@ /**

function isFloat16ArrayBits(target) {
function isFloat16BitsArray(target) {
return target instanceof Float16Array && _(target).proxy !== undefined;

@@ -411,4 +413,4 @@ }

function assertFloat16ArrayBits(target) {
if (!isFloat16ArrayBits(target)) {
function assertFloat16BitsArray(target) {
if (!isFloat16BitsArray(target)) {
throw new TypeError("This is not a Float16Array");

@@ -427,3 +429,3 @@ }

/**
* @param {Float16Array} float16bits
* @param {Float16Array} float16bitsArray
* @return {number[]}

@@ -433,8 +435,8 @@ */

function copyToArray(float16bits) {
const length = float16bits.length;
function copyToArray(float16bitsArray) {
const length = float16bitsArray.length;
const array = [];
for (let i = 0; i < length; ++i) {
array.push(convertToNumber(float16bits[i]));
array.push(convertToNumber(float16bitsArray[i]));
}

@@ -447,3 +449,3 @@

const applyHandler = {
const applyHandler = Object.freeze({
apply(func, thisArg, args) {

@@ -458,9 +460,10 @@ // peel off proxy

};
});
/** @type {ProxyHandler<Float16Array>} */
const handler = {
const handler = Object.freeze({
get(target, key) {
if (isCanonicalIntegerIndexString(key)) {
return Reflect.has(target, key) ? convertToNumber(Reflect.get(target, key)) : undefined;
const raw = Reflect.get(target, key);
return raw !== undefined ? convertToNumber(raw) : undefined;
} else {

@@ -492,3 +495,4 @@ const ret = Reflect.get(target, key);

};
});
const hasOwnProperty = Object.prototype.hasOwnProperty;
class Float16Array extends Uint16Array {

@@ -513,3 +517,3 @@ /**

const BufferConstructor = !isSharedArrayBuffer(buffer) ? SpeciesConstructor(buffer, ArrayBuffer) : ArrayBuffer;
const data = new BufferConstructor(length * 2);
const data = new BufferConstructor(length * Uint16Array.BYTES_PER_ELEMENT);
super(data); // Iterable (Array)

@@ -587,6 +591,6 @@ } else if (isIterable(input)) {

const float16bits = _(proxy).target;
const float16bitsArray = _(proxy).target;
for (let i = 0; i < length; ++i) {
float16bits[i] = roundToFloat16Bits(items[i]);
float16bitsArray[i] = roundToFloat16Bits(items[i]);
}

@@ -602,3 +606,3 @@

keys() {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
return super.keys();

@@ -613,3 +617,3 @@ }

values() {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const arrayIterator = super.values();

@@ -629,3 +633,3 @@ return wrapInArrayIterator(function* () {

entries() {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const arrayIterator = super.entries();

@@ -644,3 +648,3 @@ return wrapInArrayIterator(function* () {

at(index) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -662,3 +666,3 @@ const relativeIndex = ToIntegerOrInfinity(index);

map(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -671,7 +675,7 @@ const length = this.length;

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

@@ -697,3 +701,3 @@

filter(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -720,3 +724,3 @@ const kept = [];

reduce(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -750,3 +754,3 @@

reduceRight(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -780,3 +784,3 @@

forEach(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -794,3 +798,3 @@

find(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -812,3 +816,3 @@

findIndex(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -832,3 +836,3 @@

findLast(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -850,3 +854,3 @@

findLastIndex(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -870,3 +874,3 @@

every(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -888,3 +892,3 @@

some(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -906,3 +910,3 @@

set(input, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const targetOffset = ToIntegerOrInfinity(opts[0]);

@@ -916,5 +920,5 @@

if (isFloat16ArrayProxy(input)) {
const float16bits = _(input).target;
const float16bitsArray = _(input).target;
super.set(float16bits, targetOffset);
super.set(float16bitsArray, targetOffset);
return;

@@ -941,3 +945,3 @@ }

reverse() {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
super.reverse();

@@ -952,3 +956,3 @@ return _(this).proxy;

fill(value, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
super.fill(roundToFloat16Bits(value), ...opts);

@@ -963,3 +967,3 @@ return _(this).proxy;

copyWithin(target, start, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
super.copyWithin(target, start, ...opts);

@@ -974,6 +978,6 @@ return _(this).proxy;

sort(...opts) {
assertFloat16ArrayBits(this);
const compareFunction = opts[0] !== undefined ? opts[0] : defaultCompareFunction;
assertFloat16BitsArray(this);
const compare = opts[0] !== undefined ? opts[0] : defaultCompare;
super.sort((x, y) => {
return compareFunction(convertToNumber(x), convertToNumber(y));
return compare(convertToNumber(x), convertToNumber(y));
});

@@ -988,3 +992,3 @@ return _(this).proxy;

slice(...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const Constructor = SpeciesConstructor(this, Float16Array); // for optimization

@@ -994,4 +998,4 @@

const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length);
const float16bits = uint16.slice(...opts);
const proxy = new Float16Array(float16bits.buffer);
const float16bitsArray = uint16.slice(...opts);
const proxy = new Float16Array(float16bitsArray.buffer);
return proxy;

@@ -1046,7 +1050,7 @@ }

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

@@ -1060,3 +1064,3 @@ }

indexOf(element, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -1078,3 +1082,3 @@ let from = ToIntegerOrInfinity(opts[0]);

for (let i = from, l = length; i < l; ++i) {
if (Object.prototype.hasOwnProperty.call(this, i) && convertToNumber(this[i]) === element) {
if (hasOwnProperty.call(this, i) && convertToNumber(this[i]) === element) {
return i;

@@ -1092,3 +1096,3 @@ }

lastIndexOf(element, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -1108,3 +1112,3 @@ let from = opts.length >= 1 ? ToIntegerOrInfinity(opts[0]) : length - 1;

for (let i = from; i >= 0; --i) {
if (Object.prototype.hasOwnProperty.call(this, i) && convertToNumber(this[i]) === element) {
if (hasOwnProperty.call(this, i) && convertToNumber(this[i]) === element) {
return i;

@@ -1122,3 +1126,3 @@ }

includes(element, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -1161,3 +1165,3 @@ let from = ToIntegerOrInfinity(opts[0]);

join(...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const array = copyToArray(this);

@@ -1172,3 +1176,3 @@ return array.join(...opts);

toLocaleString(...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const array = copyToArray(this);

@@ -1183,3 +1187,3 @@ return array.toLocaleString(...opts);

get [Symbol.toStringTag]() {
if (isFloat16ArrayBits(this)) {
if (isFloat16BitsArray(this)) {
return "Float16Array";

@@ -1186,0 +1190,0 @@ }

@@ -34,3 +34,3 @@ "use strict";

function isFloat16ArrayBits(target) {
function isFloat16BitsArray(target) {
return target instanceof Float16Array && _(target).proxy !== undefined;

@@ -44,4 +44,4 @@ }

function assertFloat16ArrayBits(target) {
if (!isFloat16ArrayBits(target)) {
function assertFloat16BitsArray(target) {
if (!isFloat16BitsArray(target)) {
throw new TypeError("This is not a Float16Array");

@@ -60,3 +60,3 @@ }

/**
* @param {Float16Array} float16bits
* @param {Float16Array} float16bitsArray
* @return {number[]}

@@ -66,8 +66,8 @@ */

function copyToArray(float16bits) {
const length = float16bits.length;
function copyToArray(float16bitsArray) {
const length = float16bitsArray.length;
const array = [];
for (let i = 0; i < length; ++i) {
array.push((0, _lib.convertToNumber)(float16bits[i]));
array.push((0, _lib.convertToNumber)(float16bitsArray[i]));
}

@@ -80,3 +80,3 @@

const applyHandler = {
const applyHandler = Object.freeze({
apply(func, thisArg, args) {

@@ -91,9 +91,10 @@ // peel off proxy

};
});
/** @type {ProxyHandler<Float16Array>} */
const handler = {
const handler = Object.freeze({
get(target, key) {
if ((0, _is.isCanonicalIntegerIndexString)(key)) {
return Reflect.has(target, key) ? (0, _lib.convertToNumber)(Reflect.get(target, key)) : undefined;
const raw = Reflect.get(target, key);
return raw !== undefined ? (0, _lib.convertToNumber)(raw) : undefined;
} else {

@@ -125,3 +126,4 @@ const ret = Reflect.get(target, key);

};
});
const hasOwnProperty = Object.prototype.hasOwnProperty;

@@ -147,3 +149,3 @@ class Float16Array extends Uint16Array {

const BufferConstructor = !(0, _is.isSharedArrayBuffer)(buffer) ? (0, _spec.SpeciesConstructor)(buffer, ArrayBuffer) : ArrayBuffer;
const data = new BufferConstructor(length * 2);
const data = new BufferConstructor(length * Uint16Array.BYTES_PER_ELEMENT);
super(data); // Iterable (Array)

@@ -221,6 +223,6 @@ } else if ((0, _is.isIterable)(input)) {

const float16bits = _(proxy).target;
const float16bitsArray = _(proxy).target;
for (let i = 0; i < length; ++i) {
float16bits[i] = (0, _lib.roundToFloat16Bits)(items[i]);
float16bitsArray[i] = (0, _lib.roundToFloat16Bits)(items[i]);
}

@@ -236,3 +238,3 @@

keys() {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
return super.keys();

@@ -247,3 +249,3 @@ }

values() {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const arrayIterator = super.values();

@@ -263,3 +265,3 @@ return (0, _arrayIterator.wrapInArrayIterator)(function* () {

entries() {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const arrayIterator = super.entries();

@@ -278,3 +280,3 @@ return (0, _arrayIterator.wrapInArrayIterator)(function* () {

at(index) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -296,3 +298,3 @@ const relativeIndex = (0, _spec.ToIntegerOrInfinity)(index);

map(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -305,7 +307,7 @@ const length = this.length;

const float16bits = _(proxy).target;
const float16bitsArray = _(proxy).target;
for (let i = 0; i < length; ++i) {
const val = (0, _lib.convertToNumber)(this[i]);
float16bits[i] = (0, _lib.roundToFloat16Bits)(callback.call(thisArg, val, i, _(this).proxy));
float16bitsArray[i] = (0, _lib.roundToFloat16Bits)(callback.call(thisArg, val, i, _(this).proxy));
}

@@ -331,3 +333,3 @@

filter(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -354,3 +356,3 @@ const kept = [];

reduce(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -384,3 +386,3 @@

reduceRight(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -414,3 +416,3 @@

forEach(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -428,3 +430,3 @@

find(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -446,3 +448,3 @@

findIndex(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -466,3 +468,3 @@

findLast(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -484,3 +486,3 @@

findLastIndex(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -504,3 +506,3 @@

every(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -522,3 +524,3 @@

some(callback, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const thisArg = opts[0];

@@ -540,3 +542,3 @@

set(input, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const targetOffset = (0, _spec.ToIntegerOrInfinity)(opts[0]);

@@ -550,5 +552,5 @@

if (isFloat16ArrayProxy(input)) {
const float16bits = _(input).target;
const float16bitsArray = _(input).target;
super.set(float16bits, targetOffset);
super.set(float16bitsArray, targetOffset);
return;

@@ -575,3 +577,3 @@ }

reverse() {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
super.reverse();

@@ -586,3 +588,3 @@ return _(this).proxy;

fill(value, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
super.fill((0, _lib.roundToFloat16Bits)(value), ...opts);

@@ -597,3 +599,3 @@ return _(this).proxy;

copyWithin(target, start, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
super.copyWithin(target, start, ...opts);

@@ -608,6 +610,6 @@ return _(this).proxy;

sort(...opts) {
assertFloat16ArrayBits(this);
const compareFunction = opts[0] !== undefined ? opts[0] : _spec.defaultCompareFunction;
assertFloat16BitsArray(this);
const compare = opts[0] !== undefined ? opts[0] : _spec.defaultCompare;
super.sort((x, y) => {
return compareFunction((0, _lib.convertToNumber)(x), (0, _lib.convertToNumber)(y));
return compare((0, _lib.convertToNumber)(x), (0, _lib.convertToNumber)(y));
});

@@ -622,3 +624,3 @@ return _(this).proxy;

slice(...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const Constructor = (0, _spec.SpeciesConstructor)(this, Float16Array); // for optimization

@@ -628,4 +630,4 @@

const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length);
const float16bits = uint16.slice(...opts);
const proxy = new Float16Array(float16bits.buffer);
const float16bitsArray = uint16.slice(...opts);
const proxy = new Float16Array(float16bitsArray.buffer);
return proxy;

@@ -680,7 +682,7 @@ }

subarray(...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length);
const float16bits = uint16.subarray(...opts);
const float16bitsArray = uint16.subarray(...opts);
const Constructor = (0, _spec.SpeciesConstructor)(this, Float16Array);
const array = new Constructor(float16bits.buffer, float16bits.byteOffset, float16bits.length);
const array = new Constructor(float16bitsArray.buffer, float16bitsArray.byteOffset, float16bitsArray.length);
return array;

@@ -694,3 +696,3 @@ }

indexOf(element, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -712,3 +714,3 @@ let from = (0, _spec.ToIntegerOrInfinity)(opts[0]);

for (let i = from, l = length; i < l; ++i) {
if (Object.prototype.hasOwnProperty.call(this, i) && (0, _lib.convertToNumber)(this[i]) === element) {
if (hasOwnProperty.call(this, i) && (0, _lib.convertToNumber)(this[i]) === element) {
return i;

@@ -726,3 +728,3 @@ }

lastIndexOf(element, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -742,3 +744,3 @@ let from = opts.length >= 1 ? (0, _spec.ToIntegerOrInfinity)(opts[0]) : length - 1;

for (let i = from; i >= 0; --i) {
if (Object.prototype.hasOwnProperty.call(this, i) && (0, _lib.convertToNumber)(this[i]) === element) {
if (hasOwnProperty.call(this, i) && (0, _lib.convertToNumber)(this[i]) === element) {
return i;

@@ -756,3 +758,3 @@ }

includes(element, ...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const length = this.length;

@@ -795,3 +797,3 @@ let from = (0, _spec.ToIntegerOrInfinity)(opts[0]);

join(...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const array = copyToArray(this);

@@ -806,3 +808,3 @@ return array.join(...opts);

toLocaleString(...opts) {
assertFloat16ArrayBits(this);
assertFloat16BitsArray(this);
const array = copyToArray(this);

@@ -817,3 +819,3 @@ return array.toLocaleString(...opts);

get [Symbol.toStringTag]() {
if (isFloat16ArrayBits(this)) {
if (isFloat16BitsArray(this)) {
return "Float16Array";

@@ -820,0 +822,0 @@ }

@@ -16,3 +16,2 @@ "use strict";

const toString = Object.prototype.toString;
/**

@@ -22,3 +21,2 @@ * @param {unknown} value

*/
function isObject(value) {

@@ -36,2 +34,4 @@ return value !== null && typeof value === "object" || typeof value === "function";

}
const toString = Object.prototype.toString;
/**

@@ -42,8 +42,9 @@ * @param {unknown} value

function isDataView(value) {
return ArrayBuffer.isView(value) && toString.call(value) === "[object DataView]";
}
} // Inspired by util.types implementation of Node.js
const typedArrayTags = new Set(["[object Float32Array]", "[object Float64Array]", "[object Int8Array]", "[object Int16Array]", "[object Int32Array]", "[object Uint8Array]", "[object Uint8ClampedArray]", "[object Uint16Array]", "[object Uint32Array]", "[object BigInt64Array]", "[object BigUint64Array]"]);
const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array).prototype;
const getTypedArrayPrototypeSybolToStringTag = Object.getOwnPropertyDescriptor(TypedArrayPrototype, Symbol.toStringTag).get;
/**

@@ -55,3 +56,3 @@ * @param {unknown} value

function isTypedArray(value) {
return ArrayBuffer.isView(value) && typedArrayTags.has(toString.call(value));
return getTypedArrayPrototypeSybolToStringTag.call(value) !== undefined;
}

@@ -58,0 +59,0 @@ /**

@@ -9,3 +9,3 @@ "use strict";

exports.SpeciesConstructor = SpeciesConstructor;
exports.defaultCompareFunction = defaultCompareFunction;
exports.defaultCompare = defaultCompare;

@@ -107,3 +107,3 @@ /**

function defaultCompareFunction(x, y) {
function defaultCompare(x, y) {
const [isNaN_x, isNaN_y] = [Number.isNaN(x), Number.isNaN(y)];

@@ -110,0 +110,0 @@

{
"name": "@petamoriken/float16",
"description": "half precision floating point for JavaScript",
"version": "3.3.2",
"version": "3.3.3",
"main": "./lib/index.js",

@@ -66,3 +66,2 @@ "module": "./src/index.mjs",

"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"babel-plugin-replace-import-extension": "^1.1.1",

@@ -69,0 +68,0 @@ "browserslist": "^4.16.7",

@@ -9,12 +9,12 @@ # <a href="https://git.io/float16" target="_blank">@petamoriken/float16</a>

<p align="center">
<a href="https://www.npmjs.com/package/@petamoriken/float16">
<a href="https://www.npmjs.com/package/@petamoriken/float16" target="_blank">
<img src="https://img.shields.io/npm/dw/@petamoriken/float16?logo=npm&amp;style=flat-square" alt="npm downloads">
</a>
<a href="https://www.npmjs.com/package/@petamoriken/float16">
<a href="https://www.npmjs.com/package/@petamoriken/float16" target="_blank">
<img src="https://img.shields.io/npm/v/@petamoriken/float16.svg?label=version&amp;style=flat-square" alt="npm">
</a>
<a href="https://github.com/petamoriken/float16/blob/master/LICENSE">
<a href="https://github.com/petamoriken/float16/blob/master/LICENSE" target="_blank">
<img src="https://img.shields.io/npm/l/@petamoriken/float16.svg?style=flat-square" alt="license">
</a>
<a href="https://codecov.io/gh/petamoriken/float16">
<a href="https://codecov.io/gh/petamoriken/float16" target="_blank">
<img src="https://img.shields.io/codecov/c/gh/petamoriken/float16?logo=codecov&amp;style=flat-square" alt="codecov">

@@ -25,4 +25,4 @@ </a>

<p align="center">
<a href="https://saucelabs.com/u/petamoriken">
<img src="https://saucelabs.com/browser-matrix/petamoriken.svg?" alt="Sauce Labs browser matrix" style="background: #eee">
<a href="https://saucelabs.com/u/petamoriken" target="_blank">
<img src="https://saucelabs.com/browser-matrix/petamoriken.svg" alt="Sauce Labs browser matrix">
</a>

@@ -41,3 +41,3 @@ </p>

## Require
## Import

@@ -58,5 +58,6 @@ ### Node.js or Bundler (webpack, rollup.js, esbuild, etc)

Serve `browser/float16.mjs` / `browser/float16.js` files from your Web server as JavaScript Content-Type.
Serve `browser/float16.mjs` / `browser/float16.js` files from your Web server as the JavaScript `Content-Type`.
```html
<!-- Module Scripts -->
<script type="module">

@@ -68,2 +69,3 @@ import { Float16Array, getFloat16, setFloat16, hfround } from "DEST/TO/float16.mjs";

```html
<!-- Classic Scripts -->
<script src="DEST/TO/float16.js"></script>

@@ -75,7 +77,8 @@ <script>

Or use jsDelivr CDN.
Or use [jsDelivr](https://www.jsdelivr.com/) CDN.
```html
<!-- Module Scripts -->
<script type="module">
import { Float16Array, getFloat16, setFloat16, hfround } from "https://cdn.jsdelivr.net/npm/@petamoriken/float16/browser/float16.mjs/+esm";
import { Float16Array, getFloat16, setFloat16, hfround } from "https://cdn.jsdelivr.net/npm/@petamoriken/float16/+esm";
</script>

@@ -85,2 +88,3 @@ ```

```html
<!-- Classic Scripts -->
<script src="https://cdn.jsdelivr.net/npm/@petamoriken/float16/browser/float16.min.js"></script>

@@ -92,5 +96,6 @@ <script>

You can use ES Modules with Skypack CDN.
ES modules are also available on the [Skypack](https://www.skypack.dev/) CDN.
```html
<!-- Module Scripts -->
<script type="module">

@@ -118,5 +123,5 @@ import { Float16Array, getFloat16, setFloat16, hfround } from "https://cdn.skypack.dev/@petamoriken/float16?min";

However, this package only uses up to the ES2015 features, so you should be able to use it without any problems.
However, **this package only uses up to the ES2015 features**, so you should be able to use it without any problems.
When you build by yourself using bundler for old browsers support, please transpile JavaScript files in `src/` directory.
If you build it yourself using bundler to support older browsers, transpile the JavaScript files in the `src/` directory.

@@ -127,3 +132,3 @@ ## API

This API is similar to `TypedArray` such as `Float32Array`.
This API is similar to `TypedArray` such as `Float32Array` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)).

@@ -146,3 +151,3 @@ ```js

These APIs are similar to `DataView` methods such as `DataView#getFloat32` and `DataView#setFloat32`.
These APIs are similar to `DataView` methods such as `DataView#getFloat32` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)) and `DataView#setFloat32` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)).

@@ -180,4 +185,28 @@ ```js

## Limitations
## `Float16Array` limitations (edge cases)
### The `instanceof` operator
Since `Float16Array` is made by inheriting from `Uint16Array`, it doesn't work if the `instanceof` operator is used to detect a `Uint16Array`.
```js
new Uint16Array(10) instanceof Uint16Array; // true
new Float16Array(10) instanceof Uint16Array; // true
```
Actually, I could use `Proxy`'s `getPrototypeOf` handler to trap it, but that would be too complex and have some limitations.
In addition, it is a bad idea to use `instanceof` to detect the type of `TypedArray`, because it can't be used to detect the type of objects from other Realms, such as iframe and vm. It is recommended to use `Object#toString` or `@@toStringTag` for this purpose.
```js
function isUint16Array(target) {
if (target === null || typeof target !== "object") {
return false;
}
return Object.prototype.toString.call(target) === "[object Uint16Array]";
}
```
For Node.js, you can use `util.types.isUint16Array` ([document](https://nodejs.org/api/util.html#util_util_types_isuint16array_value)) instead. `@@toStringTag` seems to be used for [its implementation](https://github.com/nodejs/node/blob/v16.x/lib/internal/util/types.js).
### Built-in functions

@@ -196,5 +225,5 @@

### `Float16Array` prototype methods
### Prototype methods
Due to implementation reasons, some details of `Float16Array` prototype methods may differ from the ECMAScript specification. See JSDoc comments in `src/Float16Array.mjs`.
Due to implementation reasons, some details of `Float16Array` prototype methods may differ from the ECMAScript specification. See JSDoc comments in `src/Float16Array.mjs` for details.

@@ -207,3 +236,2 @@ ### WebGL

// WebGL 2 example
const vertices = new Float16Array([

@@ -217,6 +245,9 @@ -0.5, -0.5, 0,

gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Uint16Array( vertices.buffer ), gl.STATIC_DRAW); // wrap in Uint16Array
gl.enableVertexAttribArray(location);
// wrap in Uint16Array
gl.bufferData(gl.ARRAY_BUFFER, new Uint16Array(vertices.buffer), gl.STATIC_DRAW);
gl.vertexAttribPointer(location, 3, gl.HALF_FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.enableVertexAttribArray(location);
```

@@ -223,0 +254,0 @@

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