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.5.0 to 3.5.1

lib/_util/arrayIterator.cjs

830

browser/float16.js

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

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

@@ -6,10 +6,197 @@ const float16 = (function (exports) {

/* eslint-disable no-restricted-globals */
const { bind, call } = Function.prototype;
/** @type {(target: any) => any} */
const uncurryThis = bind.bind(call);
/** @type {(target: any, key: string | symbol) => any} */
function uncurryThisGetter(target, key) {
return uncurryThis(
ReflectGetOwnPropertyDescriptor(
target,
key
).get
);
}
// Reflect
const {
apply: ReflectApply,
get: ReflectGet,
getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
getPrototypeOf: ReflectGetPrototypeOf,
has: ReflectHas,
ownKeys: ReflectOwnKeys,
set: ReflectSet,
setPrototypeOf: ReflectSetPrototypeOf,
} = Reflect;
// Proxy
const NativeProxy = Proxy;
// Number
const NativeNumber = Number;
const {
isFinite: NumberIsFinite,
isNaN: NumberIsNaN,
} = NativeNumber;
// Symbol
const {
iterator: SymbolIterator,
species: SymbolSpecies,
toStringTag: SymbolToStringTag,
for: SymbolFor,
} = Symbol;
// Array
const NativeArray = Array;
const ArrayIsArray = NativeArray.isArray;
const ArrayPrototype = NativeArray.prototype;
/** @type {(array: Array<unknown>, separator?: string) => string} */
const ArrayPrototypeJoin = uncurryThis(ArrayPrototype.join);
/** @type {<T>(array: Array<T>, ...items: T[]) => number} */
const ArrayPrototypePush = uncurryThis(ArrayPrototype.push);
/** @type {(array: Array<unknown>) => string} */
const ArrayPrototypeToLocaleString = uncurryThis(
ArrayPrototype.toLocaleString
);
// Object
const NativeObject = Object;
const {
create: ObjectCreate,
defineProperty: ObjectDefineProperty,
freeze: ObjectFreeze,
is: ObjectIs,
} = NativeObject;
/** @type {(object: object, key: PropertyKey) => boolean} */
const ObjectHasOwn = /** @type {any} */ (NativeObject).hasOwn ||
uncurryThis(NativeObject.prototype.hasOwnProperty);
// Math
const MathTrunc = Math.trunc;
// ArrayBuffer
const NativeArrayBuffer = ArrayBuffer;
// TypedArray
/** @typedef {Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array} TypedArray */
/** @type {any} */
const TypedArray = ReflectGetPrototypeOf(Uint8Array);
const TypedArrayPrototype = TypedArray.prototype;
/** @type {(typedArray: TypedArray) => IterableIterator<number>} */
const TypedArrayPrototypeKeys = uncurryThis(TypedArrayPrototype.keys);
/** @type {(typedArray: TypedArray) => IterableIterator<number>} */
const TypedArrayPrototypeValues = uncurryThis(
TypedArrayPrototype.values
);
/** @type {(typedArray: TypedArray) => IterableIterator<[number, number]>} */
const TypedArrayPrototypeEntries = uncurryThis(
TypedArrayPrototype.entries
);
/** @type {(typedArray: TypedArray, array: ArrayLike<number>, offset?: number) => void} */
const TypedArrayPrototypeSet = uncurryThis(TypedArrayPrototype.set);
/** @type {<T extends TypedArray>(typedArray: T) => T} */
const TypedArrayPrototypeReverse = uncurryThis(
TypedArrayPrototype.reverse
);
/** @type {<T extends TypedArray>(typedArray: T, value: number, start?: number, end?: number) => T} */
const TypedArrayPrototypeFill = uncurryThis(TypedArrayPrototype.fill);
/** @type {<T extends TypedArray>(typedArray: T, target: number, start: number, end?: number) => T} */
const TypedArrayPrototypeCopyWithin = uncurryThis(
TypedArrayPrototype.copyWithin
);
/** @type {<T extends TypedArray>(typedArray: T, compareFn?: (a: number, b: number) => number) => T} */
const TypedArrayPrototypeSort = uncurryThis(TypedArrayPrototype.sort);
/** @type {<T extends TypedArray>(typedArray: T, start?: number, end?: number) => T} */
const TypedArrayPrototypeSlice = uncurryThis(TypedArrayPrototype.slice);
/** @type {<T extends TypedArray>(typedArray: T, start?: number, end?: number) => T} */
const TypedArrayPrototypeSubarray = uncurryThis(
TypedArrayPrototype.subarray
);
/** @type {((typedArray: TypedArray) => ArrayBuffer)} */
const TypedArrayPrototypeGetBuffer = uncurryThis(
ReflectGetOwnPropertyDescriptor(
TypedArrayPrototype,
"buffer"
).get
);
/** @type {((typedArray: TypedArray) => number)} */
const TypedArrayPrototypeGetByteOffset = uncurryThisGetter(
TypedArrayPrototype,
"byteOffset"
);
/** @type {((typedArray: TypedArray) => number)} */
const TypedArrayPrototypeGetLength = uncurryThisGetter(
TypedArrayPrototype,
"length"
);
/** @type {(target: unknown) => string} */
const TypedArrayPrototypeGetSymbolToStringTag = uncurryThisGetter(
TypedArrayPrototype,
SymbolToStringTag
);
// Uint16Array
const NativeUint16Array = Uint16Array;
const Uint16ArrayFrom = TypedArray.from.bind(NativeUint16Array);
// Uint32Array
const NativeUint32Array = Uint32Array;
// Float32Array
const NativeFloat32Array = Float32Array;
// Iterator
const IteratorPrototype = ReflectGetPrototypeOf(
ReflectGetPrototypeOf([][SymbolIterator]())
);
// Generator
const GeneratorPrototype = (function* () {}).constructor.prototype.prototype;
/** @type {<T = unknown, TReturn = any, TNext = unknown>(generator: Generator<T, TReturn, TNext>, value?: TNext) => T} */
const GeneratorPrototypeNext = uncurryThis(GeneratorPrototype.next);
// DataView
const DataViewPrototype = DataView.prototype;
/** @type {(dataView: DataView, byteOffset: number, littleEndian?: boolean) => number} */
const DataViewPrototypeGetUint16 = uncurryThis(
DataViewPrototype.getUint16
);
/** @type {(dataView: DataView, byteOffset: number, value: number, littleEndian?: boolean) => void} */
const DataViewPrototypeSetUint16 = uncurryThis(
DataViewPrototype.setUint16
);
// Error
const NativeTypeError = TypeError;
const NativeRangeError = RangeError;
// Set
const NativeSet = Set;
const SetPrototype = NativeSet.prototype;
/** @type {<T>(set: Set<T>, value: T) => Set<T>} */
const SetPrototypeAdd = uncurryThis(SetPrototype.add);
/** @type {<T>(set: Set<T>, value: T) => boolean} */
const SetPrototypeHas = uncurryThis(SetPrototype.has);
// WeakMap
const NativeWeakMap = WeakMap;
const WeakMapPrototype = NativeWeakMap.prototype;
/** @type {<K extends {}, V>(weakMap: WeakMap<K, V>, key: K) => V} */
const WeakMapPrototypeGet = uncurryThis(WeakMapPrototype.get);
/** @type {<K extends {}, V>(weakMap: WeakMap<K, V>, key: K, value: V) => WeakMap} */
const WeakMapPrototypeSet = uncurryThis(WeakMapPrototype.set);
// algorithm: http://fox-toolkit.org/ftp/fasthalffloatconversion.pdf
const buffer = new ArrayBuffer(4);
const floatView = new Float32Array(buffer);
const uint32View = new Uint32Array(buffer);
const buffer = new NativeArrayBuffer(4);
const floatView = new NativeFloat32Array(buffer);
const uint32View = new NativeUint32Array(buffer);
const baseTable = new Uint32Array(512);
const shiftTable = new Uint32Array(512);
const baseTable = new NativeUint32Array(512);
const shiftTable = new NativeUint32Array(512);

@@ -59,7 +246,7 @@ for (let i = 0; i < 256; ++i) {

*
* @param {number} num - double float
* @param {unknown} num - double float
* @returns {number} half float number bits
*/
function roundToFloat16Bits(num) {
floatView[0] = num;
floatView[0] = /** @type {any} */ (num);
const f = uint32View[0];

@@ -70,5 +257,5 @@ const e = (f >> 23) & 0x1ff;

const mantissaTable = new Uint32Array(2048);
const exponentTable = new Uint32Array(64);
const offsetTable = new Uint32Array(64);
const mantissaTable = new NativeUint32Array(2048);
const exponentTable = new NativeUint32Array(64);
const offsetTable = new NativeUint32Array(64);

@@ -135,9 +322,9 @@ mantissaTable[0] = 0;

if (typeof num === "bigint") {
throw TypeError("Cannot convert a BigInt value to a number");
throw NativeTypeError("Cannot convert a BigInt value to a number");
}
num = Number(num);
num = NativeNumber(num);
// for optimization
if (!Number.isFinite(num) || num === 0) {
if (!NumberIsFinite(num) || num === 0) {
return num;

@@ -150,27 +337,11 @@ }

/** @returns {(self: object) => object} */
function createPrivateStorage() {
const wm = new WeakMap();
/** @type {WeakMap<{}, Generator<any>>} */
const generators = new NativeWeakMap();
return (self) => {
const storage = wm.get(self);
if (storage !== undefined) {
return storage;
}
const obj = Object.create(null);
wm.set(self, obj);
return obj;
};
}
const _$1 = createPrivateStorage();
const IteratorPrototype = Reflect.getPrototypeOf(Reflect.getPrototypeOf([][Symbol.iterator]()));
/** @see https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object */
const ArrayIteratorPrototype = Object.create(IteratorPrototype, {
const ArrayIteratorPrototype = ObjectCreate(IteratorPrototype, {
next: {
value: function next() {
return _$1(this).iterator.next();
const generator = WeakMapPrototypeGet(generators, this);
return GeneratorPrototypeNext(generator);
},

@@ -181,3 +352,3 @@ writable: true,

[Symbol.toStringTag]: {
[SymbolToStringTag]: {
value: "Array Iterator",

@@ -188,9 +359,6 @@ configurable: true,

/**
* @param {Iterator<T>} iterator
* @returns {IterableIterator<T>}
*/
function wrapInArrayIterator(iterator) {
const arrayIterator = Object.create(ArrayIteratorPrototype);
_$1(arrayIterator).iterator = iterator;
/** @type {<T>(generator: Generator<T>) => IterableIterator<T>} */
function wrapInArrayIterator(generator) {
const arrayIterator = ObjectCreate(ArrayIteratorPrototype);
WeakMapPrototypeSet(generators, arrayIterator, generator);
return arrayIterator;

@@ -201,6 +369,7 @@ }

* @param {unknown} value
* @returns {value is object}
* @returns {value is {}}
*/
function isObject(value) {
return (value !== null && typeof value === "object") || typeof value === "function";
return (value !== null && typeof value === "object") ||
typeof value === "function";
}

@@ -210,3 +379,3 @@

* @param {unknown} value
* @returns {value is object}
* @returns {value is {}}
*/

@@ -218,10 +387,10 @@ function isObjectLike(value) {

// Inspired by util.types implementation of Node.js
const getTypedArrayPrototypeSymbolToStringTag = Reflect.getOwnPropertyDescriptor(Reflect.getPrototypeOf(Uint8Array).prototype, Symbol.toStringTag).get;
/** @typedef {Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array} TypedArray */
/**
* @param {unknown} value
* @returns {value is Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array}
* @returns {value is TypedArray}
*/
function isTypedArray(value) {
return getTypedArrayPrototypeSymbolToStringTag.call(value) !== undefined;
return TypedArrayPrototypeGetSymbolToStringTag(value) !== undefined;
}

@@ -231,15 +400,8 @@

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

@@ -249,22 +411,6 @@

* @param {unknown} value
* @returns {value is DataView}
*/
function isDataView(value) {
if (!ArrayBuffer.isView(value)) {
return false;
}
if (isTypedArray(value)) {
return false;
}
return true;
}
/**
* @param {unknown} value
* @returns {value is ArrayBuffer}
*/
function isArrayBuffer(value) {
return isObjectLike(value) && value[Symbol.toStringTag] === "ArrayBuffer";
return isObjectLike(value) && value[SymbolToStringTag] === "ArrayBuffer";
}

@@ -277,3 +423,4 @@

function isSharedArrayBuffer(value) {
return isObjectLike(value) && value[Symbol.toStringTag] === "SharedArrayBuffer";
return isObjectLike(value) &&
value[SymbolToStringTag] === "SharedArrayBuffer";
}

@@ -283,6 +430,7 @@

* @param {unknown} value
* @returns {value is Iterable<any>}
* @throws {TypeError}
* @returns {value is Iterable<unknown>}
*/
function isIterable(value) {
return isObject(value) && typeof value[Symbol.iterator] === "function";
return typeof value[SymbolIterator] === "function";
}

@@ -292,11 +440,11 @@

* @param {unknown} value
* @returns {value is any[]}
* @returns {value is unknown[]}
*/
function isOrdinaryArray(value) {
if (!Array.isArray(value)) {
if (!ArrayIsArray(value)) {
return false;
}
const iterator = value[Symbol.iterator]();
if (iterator[Symbol.toStringTag] !== "Array Iterator") {
const iterator = value[SymbolIterator]();
if (iterator[SymbolToStringTag] !== "Array Iterator") {
return false;

@@ -310,3 +458,3 @@ }

* @param {unknown} value
* @returns {value is Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array}
* @returns {value is TypedArray}
*/

@@ -318,4 +466,4 @@ function isOrdinaryTypedArray(value) {

const iterator = value[Symbol.iterator]();
if (iterator[Symbol.toStringTag] !== "Array Iterator") {
const iterator = value[SymbolIterator]();
if (iterator[SymbolToStringTag] !== "Array Iterator") {
return false;

@@ -336,3 +484,3 @@ }

const number = Number(value);
const number = NativeNumber(value);
if (value !== number + "") {

@@ -342,7 +490,7 @@ return false;

if (!Number.isFinite(number)) {
if (!NumberIsFinite(number)) {
return false;
}
if (number !== Math.trunc(number)) {
if (number !== MathTrunc(number)) {
return false;

@@ -361,12 +509,12 @@ }

if (typeof target === "bigint") {
throw TypeError("Cannot convert a BigInt value to a number");
throw NativeTypeError("Cannot convert a BigInt value to a number");
}
const number = Number(target);
const number = NativeNumber(target);
if (Number.isNaN(number) || number === 0) {
if (NumberIsNaN(number) || number === 0) {
return 0;
}
return Math.trunc(number);
return MathTrunc(number);
}

@@ -385,3 +533,5 @@

return length < Number.MAX_SAFE_INTEGER ? length : Number.MAX_SAFE_INTEGER;
return length < NativeNumber.MAX_SAFE_INTEGER
? length
: NativeNumber.MAX_SAFE_INTEGER;
}

@@ -396,6 +546,6 @@

if (!isObject(arrayLike)) {
throw TypeError("This is not a object");
throw NativeTypeError("This is not a object");
}
return ToLength(arrayLike.length);
return ToLength(/** @type {any} */ (arrayLike).length);
}

@@ -406,8 +556,8 @@

* @param {object} target
* @param {Function} defaultConstructor
* @returns {Function}
* @param {{ new(...args: any[]): any; }} defaultConstructor
* @returns {{ new(...args: any[]): any; }}
*/
function SpeciesConstructor(target, defaultConstructor) {
if (!isObject(target)) {
throw TypeError("This is not a object");
throw NativeTypeError("This is not a object");
}

@@ -420,6 +570,6 @@

if (!isObject(constructor)) {
throw TypeError("Constructor is not a object");
throw NativeTypeError("Constructor is not a object");
}
const species = constructor[Symbol.species];
const species = constructor[SymbolSpecies];
if (species == null) {

@@ -441,4 +591,4 @@ return defaultConstructor;

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

@@ -466,4 +616,4 @@ if (isNaN_x && isNaN_y) {

if (x === 0 && y === 0) {
const isPlusZero_x = Object.is(x, 0);
const isPlusZero_y = Object.is(y, 0);
const isPlusZero_x = ObjectIs(x, 0);
const isPlusZero_y = ObjectIs(y, 0);

@@ -482,13 +632,7 @@ if (!isPlusZero_x && isPlusZero_y) {

const hasOwnProperty = Object.prototype.hasOwnProperty;
const brand = SymbolFor("__Float16Array__");
/** @type {(object: object, key: PropertyKey) => boolean} */
const hasOwn = Object.hasOwn || function hasOwn(object, key) {
return hasOwnProperty.call(object, key);
};
/** @type {WeakMap<Float16Array, Uint16Array & { __float16bits: never }>} */
const targets = new NativeWeakMap();
const brand = Symbol.for("__Float16Array__");
const _ = createPrivateStorage();
/**

@@ -503,3 +647,3 @@ * @param {unknown} target

const prototype = Reflect.getPrototypeOf(target);
const prototype = ReflectGetPrototypeOf(target);
if (!isObjectLike(prototype)) {

@@ -514,6 +658,6 @@ return false;

if (!isObject(constructor)) {
throw TypeError("Constructor is not a object");
throw NativeTypeError("Constructor is not a object");
}
return Reflect.has(constructor, brand);
return ReflectHas(constructor, brand);
}

@@ -531,15 +675,8 @@

* @param {unknown} target
* @returns {target is Uint16Array & { __float16bits: never }}
*/
function isFloat16BitsArray(target) {
return hasFloat16ArrayBrand(target) && isUint16Array(target);
}
/**
* @param {unknown} target
* @throws {TypeError}
* @returns {asserts target is Float16Array}
*/
function assertFloat16Array(target) {
if (!isFloat16Array(target)) {
throw new TypeError("This is not a Float16Array");
throw new NativeTypeError("This is not a Float16Array");
}

@@ -551,2 +688,3 @@ }

* @throws {TypeError}
* @returns {asserts target is Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float16Array|Float32Array|Float64Array}
*/

@@ -559,7 +697,9 @@ function assertSpeciesTypedArray(target) {

if (!isTypedArray(target)) {
throw new TypeError("SpeciesConstructor didn't return TypedArray");
throw new NativeTypeError("SpeciesConstructor didn't return TypedArray");
}
if (isBigIntTypedArray(target)) {
throw new TypeError("Cannot mix BigInt and other types, use explicit conversions");
throw new NativeTypeError(
"Cannot mix BigInt and other types, use explicit conversions"
);
}

@@ -573,11 +713,14 @@ }

function getFloat16BitsArray(float16) {
let target = _(float16).target;
// from other realms
if (target === undefined) {
const clone = new Float16Array(float16.buffer, float16.byteOffset, float16.length);
target = _(clone).target;
const target = WeakMapPrototypeGet(targets, float16);
if (target !== undefined) {
return target;
}
return target;
// from another Float16Array instance (a different version?)
const cloned = new Float16Array(
float16.buffer,
float16.byteOffset,
float16.length
);
return WeakMapPrototypeGet(targets, cloned);
}

@@ -590,3 +733,3 @@

function copyToArray(float16bitsArray) {
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);

@@ -601,9 +744,12 @@ const array = [];

const TypedArrayPrototype = Reflect.getPrototypeOf(Uint8Array).prototype;
const TypedArrayPrototypeGetters = new NativeSet();
for (const key of ReflectOwnKeys(TypedArrayPrototype)) {
// @@toStringTag method is defined in Float16Array.prototype
if (key === SymbolToStringTag) {
continue;
}
const TypedArrayPrototypeGetters = new Set();
for (const key of Reflect.ownKeys(TypedArrayPrototype)) {
const descriptor = Object.getOwnPropertyDescriptor(TypedArrayPrototype, key);
if (hasOwn(descriptor, "get")) {
TypedArrayPrototypeGetters.add(key);
const descriptor = ReflectGetOwnPropertyDescriptor(TypedArrayPrototype, key);
if (ObjectHasOwn(descriptor, "get")) {
SetPrototypeAdd(TypedArrayPrototypeGetters, key);
}

@@ -613,21 +759,22 @@ }

/** @type {ProxyHandler<Float16Array>} */
const handler = Object.freeze({
const handler = ObjectFreeze({
get(target, key, receiver) {
if (isCanonicalIntegerIndexString(key) && hasOwn(target, key)) {
return convertToNumber(Reflect.get(target, key));
if (isCanonicalIntegerIndexString(key) && ObjectHasOwn(target, key)) {
return convertToNumber(ReflectGet(target, key));
}
if (TypedArrayPrototypeGetters.has(key)) {
return Reflect.get(target, key);
// %TypedArray%.prototype getter properties cannot called by Proxy receiver
if (SetPrototypeHas(TypedArrayPrototypeGetters, key)) {
return ReflectGet(target, key);
}
return Reflect.get(target, key, receiver);
return ReflectGet(target, key, receiver);
},
set(target, key, value, receiver) {
if (isCanonicalIntegerIndexString(key) && hasOwn(target, key)) {
return Reflect.set(target, key, roundToFloat16Bits(value));
if (isCanonicalIntegerIndexString(key) && ObjectHasOwn(target, key)) {
return ReflectSet(target, key, roundToFloat16Bits(value));
}
return Reflect.set(target, key, value, receiver);
return ReflectSet(target, key, value, receiver);
},

@@ -637,7 +784,5 @@ });

/** limitation: `Object.getPrototypeOf(Float16Array)` returns `Uint16Array` */
class Float16Array extends Uint16Array {
class Float16Array extends NativeUint16Array {
/** @see https://tc39.es/ecma262/#sec-typedarray */
constructor(input, byteOffset, length) {
// input Float16Array
if (isFloat16Array(input)) {

@@ -647,6 +792,4 @@ // peel off Proxy

super(float16bitsArray);
// object without ArrayBuffer
} else if (isObject(input) && !isArrayBuffer(input)) {
/** @type {ArrayLike<number>} */
} else if (isObject(input) && !isArrayBuffer(input)) { // object without ArrayBuffer
/** @type {ArrayLike<unknown>} */
let list;

@@ -656,19 +799,24 @@ /** @type {number} */

// TypedArray
if (isTypedArray(input)) {
if (isTypedArray(input)) { // TypedArray
if (isBigIntTypedArray(input)) {
throw new TypeError("Cannot mix BigInt and other types, use explicit conversions");
throw new NativeTypeError(
"Cannot mix BigInt and other types, use explicit conversions"
);
}
list = input;
length = input.length;
length = TypedArrayPrototypeGetLength(input);
const buffer = input.buffer;
/** @type {ArrayBufferConstructor} */
const BufferConstructor = !isSharedArrayBuffer(buffer) ? SpeciesConstructor(buffer, ArrayBuffer) : ArrayBuffer;
const data = new BufferConstructor(length * Float16Array.BYTES_PER_ELEMENT);
const buffer = TypedArrayPrototypeGetBuffer(input);
const BufferConstructor = !isSharedArrayBuffer(buffer)
? /** @type {ArrayBufferConstructor} */ (SpeciesConstructor(
buffer,
NativeArrayBuffer
))
: NativeArrayBuffer;
const data = new BufferConstructor(
length * Float16Array.BYTES_PER_ELEMENT
);
super(data);
// Iterable (Array)
} else if (isIterable(input)) {
} else if (isIterable(input)) { // Iterable (Array)
// for optimization

@@ -679,3 +827,2 @@ if (isOrdinaryArray(input)) {

super(length);
} else {

@@ -686,6 +833,4 @@ list = [...input];

}
// ArrayLike
} else {
list = input;
} else { // ArrayLike
list = /** @type {ArrayLike<unknown>} */ (input);
length = LengthOfArrayLike(input);

@@ -700,5 +845,3 @@ super(length);

}
// primitive, ArrayBuffer
} else {
} else { // primitive, ArrayBuffer
switch (arguments.length) {

@@ -722,2 +865,3 @@ case 0:

default:
// @ts-ignore
super(...arguments);

@@ -727,6 +871,6 @@ }

const proxy = new Proxy(this, handler);
const proxy = new NativeProxy(this, handler);
// proxy private storage
_(proxy).target = this;
WeakMapPrototypeSet(targets, proxy, /** @type {any} */ (this));

@@ -744,4 +888,6 @@ return proxy;

if (!Reflect.has(Constructor, brand)) {
throw TypeError("This constructor is not a subclass of Float16Array");
if (!ReflectHas(Constructor, brand)) {
throw NativeTypeError(
"This constructor is not a subclass of Float16Array"
);
}

@@ -752,8 +898,19 @@

if (isFloat16Array(src) && opts.length === 0) {
const uint16 = new Uint16Array(src.buffer, src.byteOffset, src.length);
return new Float16Array(uint16.slice().buffer);
const float16bitsArray = getFloat16BitsArray(src);
const uint16 = new NativeUint16Array(
TypedArrayPrototypeGetBuffer(float16bitsArray),
TypedArrayPrototypeGetByteOffset(float16bitsArray),
TypedArrayPrototypeGetLength(float16bitsArray)
);
return new Float16Array(
TypedArrayPrototypeGetBuffer(TypedArrayPrototypeSlice(uint16))
);
}
if (opts.length === 0) {
return new Float16Array(Uint16Array.from(src, roundToFloat16Bits).buffer);
return new Float16Array(
TypedArrayPrototypeGetBuffer(
Uint16ArrayFrom(src, roundToFloat16Bits)
)
);
}

@@ -764,8 +921,14 @@

return new Float16Array(Uint16Array.from(src, function (val, ...args) {
return roundToFloat16Bits(mapFunc.call(this, val, ...args));
}, thisArg).buffer);
return new Float16Array(
TypedArrayPrototypeGetBuffer(
Uint16ArrayFrom(src, function (val, ...args) {
return roundToFloat16Bits(
ReflectApply(mapFunc, this, [val, ...args])
);
}, thisArg)
)
);
}
/** @type {ArrayLike<number>} */
/** @type {ArrayLike<unknown>} */
let list;

@@ -775,8 +938,10 @@ /** @type {number} */

// Iterable (TypedArray, Array)
if (isIterable(src)) {
if (isIterable(src)) { // Iterable (TypedArray, Array)
// for optimization
if (isOrdinaryArray(src) || isOrdinaryTypedArray(src)) {
if (isOrdinaryArray(src)) {
list = src;
length = src.length;
} else if (isOrdinaryTypedArray(src)) {
list = src;
length = TypedArrayPrototypeGetLength(src);
} else {

@@ -786,5 +951,3 @@ list = [...src];

}
// ArrayLike
} else {
} else { // ArrayLike
list = src;

@@ -798,5 +961,4 @@ length = LengthOfArrayLike(src);

for (let i = 0; i < length; ++i) {
array[i] = list[i];
array[i] = /** @type {number} */ (list[i]);
}
} else {

@@ -806,3 +968,3 @@ const mapFunc = opts[0];

for (let i = 0; i < length; ++i) {
array[i] = mapFunc.call(thisArg, list[i], i);
array[i] = ReflectApply(mapFunc, thisArg, [list[i], i]);
}

@@ -822,4 +984,6 @@ }

if (!Reflect.has(Constructor, brand)) {
throw TypeError("This constructor is not a subclass of Float16Array");
if (!ReflectHas(Constructor, brand)) {
throw NativeTypeError(
"This constructor is not a subclass of Float16Array"
);
}

@@ -853,4 +1017,5 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
return Reflect.apply(super.keys, getFloat16BitsArray(this), []);
return TypedArrayPrototypeKeys(float16bitsArray);
}

@@ -865,6 +1030,6 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const arrayIterator = Reflect.apply(super.values, getFloat16BitsArray(this), []);
return wrapInArrayIterator((function* () {
for (const val of arrayIterator) {
for (const val of TypedArrayPrototypeValues(float16bitsArray)) {
yield convertToNumber(val);

@@ -882,9 +1047,9 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const arrayIterator = Reflect.apply(super.entries, getFloat16BitsArray(this), []);
return wrapInArrayIterator((function* () {
for (const [i, val] of arrayIterator) {
yield [i, convertToNumber(val)];
return (wrapInArrayIterator((function* () {
for (const [i, val] of TypedArrayPrototypeEntries(float16bitsArray)) {
yield /** @type {[Number, number]} */ ([i, convertToNumber(val)]);
}
})());
})()));
}

@@ -895,6 +1060,5 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const relativeIndex = ToIntegerOrInfinity(index);

@@ -913,6 +1077,5 @@ const k = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];

@@ -929,3 +1092,5 @@

const val = convertToNumber(float16bitsArray[i]);
array[i] = roundToFloat16Bits(callback.call(thisArg, val, i, this));
array[i] = roundToFloat16Bits(
ReflectApply(callback, thisArg, [val, i, this])
);
}

@@ -941,6 +1106,6 @@

const val = convertToNumber(float16bitsArray[i]);
array[i] = callback.call(thisArg, val, i, this);
array[i] = ReflectApply(callback, thisArg, [val, i, this]);
}
return array;
return /** @type {any} */ (array);
}

@@ -951,6 +1116,5 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];

@@ -961,4 +1125,4 @@

const val = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, val, i, this)) {
kept.push(val);
if (ReflectApply(callback, thisArg, [val, i, this])) {
ArrayPrototypePush(kept, val);
}

@@ -971,3 +1135,3 @@ }

return array;
return /** @type {any} */ (array);
}

@@ -978,8 +1142,7 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
if (length === 0 && opts.length === 0) {
throw TypeError("Reduce of empty array with no initial value");
throw NativeTypeError("Reduce of empty array with no initial value");
}

@@ -997,3 +1160,8 @@

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

@@ -1007,8 +1175,7 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
if (length === 0 && opts.length === 0) {
throw TypeError("Reduce of empty array with no initial value");
throw NativeTypeError("Reduce of empty array with no initial value");
}

@@ -1026,3 +1193,8 @@

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

@@ -1036,10 +1208,13 @@

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

@@ -1051,6 +1226,5 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];

@@ -1060,3 +1234,3 @@

const value = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, value, i, this)) {
if (ReflectApply(callback, thisArg, [value, i, this])) {
return value;

@@ -1070,6 +1244,5 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];

@@ -1079,3 +1252,3 @@

const value = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, value, i, this)) {
if (ReflectApply(callback, thisArg, [value, i, this])) {
return i;

@@ -1091,6 +1264,5 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];

@@ -1100,3 +1272,3 @@

const value = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, value, i, this)) {
if (ReflectApply(callback, thisArg, [value, i, this])) {
return value;

@@ -1110,6 +1282,5 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];

@@ -1119,3 +1290,3 @@

const value = convertToNumber(float16bitsArray[i]);
if (callback.call(thisArg, value, i, this)) {
if (ReflectApply(callback, thisArg, [value, i, this])) {
return i;

@@ -1131,10 +1302,15 @@ }

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

@@ -1150,10 +1326,15 @@ }

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

@@ -1169,10 +1350,19 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const targetOffset = ToIntegerOrInfinity(opts[0]);
if (targetOffset < 0) {
throw RangeError("Offset is out of bounds");
throw NativeRangeError("Offset is out of bounds");
}
if (input == null) {
throw NativeTypeError(
"Cannot convert undefined or null to object"
);
}
if (isBigIntTypedArray(input)) {
throw new TypeError("Cannot mix BigInt and other types, use explicit conversions");
throw new NativeTypeError(
"Cannot mix BigInt and other types, use explicit conversions"
);
}

@@ -1183,17 +1373,16 @@

// peel off Proxy
return Reflect.apply(super.set, getFloat16BitsArray(this), [
return TypedArrayPrototypeSet(
getFloat16BitsArray(this),
getFloat16BitsArray(input),
targetOffset,
]);
targetOffset
);
}
const float16bitsArray = getFloat16BitsArray(this);
const targetLength = TypedArrayPrototypeGetLength(float16bitsArray);
const targetLength = float16bitsArray.length;
const src = Object(input);
const src = NativeObject(input);
const srcLength = LengthOfArrayLike(src);
if (targetOffset === Infinity || srcLength + targetOffset > targetLength) {
throw RangeError("Offset is out of bounds");
throw NativeRangeError("Offset is out of bounds");
}

@@ -1209,4 +1398,5 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
Reflect.apply(super.reverse, getFloat16BitsArray(this), []);
TypedArrayPrototypeReverse(float16bitsArray);

@@ -1219,4 +1409,9 @@ return this;

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
Reflect.apply(super.fill, getFloat16BitsArray(this), [roundToFloat16Bits(value), ...opts]);
TypedArrayPrototypeFill(
float16bitsArray,
roundToFloat16Bits(value),
...opts
);

@@ -1229,4 +1424,5 @@ return this;

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
Reflect.apply(super.copyWithin, getFloat16BitsArray(this), [target, start, ...opts]);
TypedArrayPrototypeCopyWithin(float16bitsArray, target, start, ...opts);

@@ -1239,5 +1435,8 @@ return this;

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

@@ -1250,3 +1449,2 @@ return this;

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);

@@ -1258,7 +1456,15 @@

if (Constructor === Float16Array) {
const uint16 = new Uint16Array(float16bitsArray.buffer, float16bitsArray.byteOffset, float16bitsArray.length);
return new Float16Array(uint16.slice(...opts).buffer);
const uint16 = new NativeUint16Array(
TypedArrayPrototypeGetBuffer(float16bitsArray),
TypedArrayPrototypeGetByteOffset(float16bitsArray),
TypedArrayPrototypeGetLength(float16bitsArray)
);
return new Float16Array(
TypedArrayPrototypeGetBuffer(
TypedArrayPrototypeSlice(uint16, ...opts)
)
);
}
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const start = ToIntegerOrInfinity(opts[0]);

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

return array;
return /** @type {any} */ (array);
}

@@ -1307,3 +1513,2 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);

@@ -1313,9 +1518,17 @@

const uint16 = new Uint16Array(float16bitsArray.buffer, float16bitsArray.byteOffset, float16bitsArray.length);
const uint16Subarray = uint16.subarray(...opts);
const uint16 = new NativeUint16Array(
TypedArrayPrototypeGetBuffer(float16bitsArray),
TypedArrayPrototypeGetByteOffset(float16bitsArray),
TypedArrayPrototypeGetLength(float16bitsArray)
);
const uint16Subarray = TypedArrayPrototypeSubarray(uint16, ...opts);
const array = new Constructor(uint16Subarray.buffer, uint16Subarray.byteOffset, uint16Subarray.length);
const array = new Constructor(
TypedArrayPrototypeGetBuffer(uint16Subarray),
TypedArrayPrototypeGetByteOffset(uint16Subarray),
TypedArrayPrototypeGetLength(uint16Subarray)
);
assertSpeciesTypedArray(array);
return array;
return /** @type {any} */ (array);
}

@@ -1326,6 +1539,5 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);

@@ -1345,3 +1557,6 @@ let from = ToIntegerOrInfinity(opts[0]);

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

@@ -1357,6 +1572,5 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);

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

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

@@ -1387,6 +1604,5 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = float16bitsArray.length;
const length = TypedArrayPrototypeGetLength(float16bitsArray);

@@ -1405,7 +1621,7 @@ let from = ToIntegerOrInfinity(opts[0]);

const isNaN = Number.isNaN(element);
const isNaN = NumberIsNaN(element);
for (let i = from; i < length; ++i) {
const value = convertToNumber(float16bitsArray[i]);
if (isNaN && Number.isNaN(value)) {
if (isNaN && NumberIsNaN(value)) {
return true;

@@ -1425,7 +1641,7 @@ }

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const float16bitsArray = getFloat16BitsArray(this);
const array = copyToArray(float16bitsArray);
return array.join(...opts);
return ArrayPrototypeJoin(array, ...opts);
}

@@ -1436,13 +1652,14 @@

assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const float16bitsArray = getFloat16BitsArray(this);
const array = copyToArray(float16bitsArray);
return array.toLocaleString(...opts);
// @ts-ignore
return ArrayPrototypeToLocaleString(array, ...opts);
}
/** @see https://tc39.es/ecma262/#sec-get-%typedarray%.prototype-@@tostringtag */
get [Symbol.toStringTag]() {
if (isFloat16BitsArray(this)) {
return "Float16Array";
get [SymbolToStringTag]() {
if (isFloat16Array(this)) {
return /** @type {any} */ ("Float16Array");
}

@@ -1453,6 +1670,8 @@ }

/** @see https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */
Object.defineProperty(Float16Array, "BYTES_PER_ELEMENT", { value: Uint16Array.BYTES_PER_ELEMENT });
ObjectDefineProperty(Float16Array, "BYTES_PER_ELEMENT", {
value: NativeUint16Array.BYTES_PER_ELEMENT,
});
/** limitation: It is peaked by `Object.getOwnPropertySymbols(Float16Array)` and `Reflect.ownKeys(Float16Array)` */
Object.defineProperty(Float16Array, brand, {});
// limitation: It is peaked by `Object.getOwnPropertySymbols(Float16Array)` and `Reflect.ownKeys(Float16Array)`
ObjectDefineProperty(Float16Array, brand, {});

@@ -1462,6 +1681,8 @@ const Float16ArrayPrototype = Float16Array.prototype;

/** @see https://tc39.es/ecma262/#sec-typedarray.prototype.bytes_per_element */
Object.defineProperty(Float16ArrayPrototype, "BYTES_PER_ELEMENT", { value: Uint16Array.BYTES_PER_ELEMENT });
ObjectDefineProperty(Float16ArrayPrototype, "BYTES_PER_ELEMENT", {
value: NativeUint16Array.BYTES_PER_ELEMENT,
});
/** @see https://tc39.es/ecma262/#sec-%typedarray%.prototype-@@iterator */
Object.defineProperty(Float16ArrayPrototype, Symbol.iterator, {
ObjectDefineProperty(Float16ArrayPrototype, SymbolIterator, {
value: Float16ArrayPrototype.values,

@@ -1473,3 +1694,3 @@ writable: true,

// To make `new Float16Array() instanceof Uint16Array` returns `false`
Reflect.setPrototypeOf(Float16ArrayPrototype, TypedArrayPrototype);
ReflectSetPrototypeOf(Float16ArrayPrototype, TypedArrayPrototype);

@@ -1485,7 +1706,5 @@ /**

function getFloat16(dataView, byteOffset, ...opts) {
if (!isDataView(dataView)) {
throw new TypeError("First argument to getFloat16 must be a DataView");
}
return convertToNumber( dataView.getUint16(byteOffset, ...opts) );
return convertToNumber(
DataViewPrototypeGetUint16(dataView, byteOffset, ...opts)
);
}

@@ -1502,7 +1721,8 @@

function setFloat16(dataView, byteOffset, value, ...opts) {
if (!isDataView(dataView)) {
throw new TypeError("First argument to setFloat16 must be a DataView");
}
dataView.setUint16(byteOffset, roundToFloat16Bits(value), ...opts);
return DataViewPrototypeSetUint16(
dataView,
byteOffset,
roundToFloat16Bits(value),
...opts
);
}

@@ -1509,0 +1729,0 @@

@@ -68,3 +68,6 @@ /**

*/
every(callbackfn: (value: number, index: number, array: Float16Array) => unknown, thisArg?: any): boolean;
every(
callbackfn: (value: number, index: number, array: Float16Array) => unknown,
thisArg?: any,
): boolean;

@@ -88,3 +91,6 @@ /**

*/
filter(predicate: (value: number, index: number, array: Float16Array) => any, thisArg?: any): Float16Array;
filter(
predicate: (value: number, index: number, array: Float16Array) => any,
thisArg?: any,
): Float16Array;

@@ -100,3 +106,6 @@ /**

*/
find(predicate: (value: number, index: number, obj: Float16Array) => boolean, thisArg?: any): number | undefined;
find(
predicate: (value: number, index: number, obj: Float16Array) => boolean,
thisArg?: any,
): number | undefined;

@@ -112,3 +121,6 @@ /**

*/
findIndex(predicate: (value: number, index: number, obj: Float16Array) => boolean, thisArg?: any): number;
findIndex(
predicate: (value: number, index: number, obj: Float16Array) => boolean,
thisArg?: any,
): number;

@@ -124,3 +136,6 @@ /**

*/
findLast(predicate: (value: number, index: number, obj: Float16Array) => boolean, thisArg?: any): number | undefined;
findLast(
predicate: (value: number, index: number, obj: Float16Array) => boolean,
thisArg?: any,
): number | undefined;

@@ -136,3 +151,6 @@ /**

*/
findLastIndex(predicate: (value: number, index: number, obj: Float16Array) => boolean, thisArg?: any): number;
findLastIndex(
predicate: (value: number, index: number, obj: Float16Array) => boolean,
thisArg?: any,
): number;

@@ -146,3 +164,6 @@ /**

*/
forEach(callbackfn: (value: number, index: number, array: Float16Array) => void, thisArg?: any): void;
forEach(
callbackfn: (value: number, index: number, array: Float16Array) => void,
thisArg?: any,
): void;

@@ -192,3 +213,6 @@ /**

*/
map(callbackfn: (value: number, index: number, array: Float16Array) => number, thisArg?: any): Float16Array;
map(
callbackfn: (value: number, index: number, array: Float16Array) => number,
thisArg?: any,
): Float16Array;

@@ -205,4 +229,19 @@ /**

*/
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float16Array) => number): number;
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float16Array) => number, initialValue: number): number;
reduce(
callbackfn: (
previousValue: number,
currentValue: number,
currentIndex: number,
array: Float16Array,
) => number,
): number;
reduce(
callbackfn: (
previousValue: number,
currentValue: number,
currentIndex: number,
array: Float16Array,
) => number,
initialValue: number,
): number;

@@ -219,3 +258,11 @@ /**

*/
reduce<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Float16Array) => U, initialValue: U): U;
reduce<U>(
callbackfn: (
previousValue: U,
currentValue: number,
currentIndex: number,
array: Float16Array,
) => U,
initialValue: U,
): U;

@@ -232,4 +279,19 @@ /**

*/
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float16Array) => number): number;
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float16Array) => number, initialValue: number): number;
reduceRight(
callbackfn: (
previousValue: number,
currentValue: number,
currentIndex: number,
array: Float16Array,
) => number,
): number;
reduceRight(
callbackfn: (
previousValue: number,
currentValue: number,
currentIndex: number,
array: Float16Array,
) => number,
initialValue: number,
): number;

@@ -246,3 +308,11 @@ /**

*/
reduceRight<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: Float16Array) => U, initialValue: U): U;
reduceRight<U>(
callbackfn: (
previousValue: U,
currentValue: number,
currentIndex: number,
array: Float16Array,
) => U,
initialValue: U,
): U;

@@ -276,3 +346,6 @@ /**

*/
some(callbackfn: (value: number, index: number, array: Float16Array) => unknown, thisArg?: any): boolean;
some(
callbackfn: (value: number, index: number, array: Float16Array) => unknown,
thisArg?: any,
): boolean;

@@ -312,7 +385,11 @@ /**

readonly prototype: Float16Array;
new(): Float16Array;
new(length: number): Float16Array;
new(elements: Iterable<number>): Float16Array;
new(array: ArrayLike<number> | ArrayBufferLike): Float16Array;
new(buffer: ArrayBufferLike, byteOffset: number, length?: number): Float16Array;
new (): Float16Array;
new (length: number): Float16Array;
new (elements: Iterable<number>): Float16Array;
new (array: ArrayLike<number> | ArrayBufferLike): Float16Array;
new (
buffer: ArrayBufferLike,
byteOffset: number,
length?: number,
): Float16Array;

@@ -342,3 +419,7 @@ /**

*/
from<T>(elements: Iterable<T>, mapfn: (v: T, k: number) => number, thisArg?: any): Float16Array;
from<T>(
elements: Iterable<T>,
mapfn: (v: T, k: number) => number,
thisArg?: any,
): Float16Array;

@@ -357,3 +438,7 @@ /**

*/
from<T>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => number, thisArg?: any): Float16Array;
from<T>(
arrayLike: ArrayLike<T>,
mapfn: (v: T, k: number) => number,
thisArg?: any,
): Float16Array;
}

@@ -375,3 +460,7 @@ export declare const Float16Array: Float16ArrayConstructor;

*/
export declare function getFloat16(dataView: DataView, byteOffset: number, littleEndian?: boolean): number;
export declare function getFloat16(
dataView: DataView,
byteOffset: number,
littleEndian?: boolean,
): number;

@@ -385,3 +474,8 @@ /**

*/
export declare function setFloat16(dataView: DataView, byteOffset: number, value: number, littleEndian?: boolean): void;
export declare function setFloat16(
dataView: DataView,
byteOffset: number,
value: number,
littleEndian?: boolean,
): void;

@@ -388,0 +482,0 @@ /**

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

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

"scripts": {
"build": "yarn run build:lib; yarn run build:browser",
"build": "concurrently \"yarn:build:*\"",
"build:browser": "rollup -c",

@@ -59,7 +59,10 @@ "build:lib": "babel src -d lib --out-file-extension .cjs",

"coverage": "nyc --reporter=lcov mocha test/*.js",
"docs": "mkdir -p docs && cp README.md docs/index.md; yarn run docs:test",
"docs:test": "mkdir -p docs/test && cp browser/float16.js docs/test/float16.js; yarn run docs:test:assets; yarn run docs:test:dependencies",
"docs:test:assets": "cp test/*.js docs/test && tools/power; cp test/browser/*.html docs/test",
"docs": "mkdir -p docs && cp README.md docs/index.md && yarn run docs:test",
"docs:test": "mkdir -p docs/test && concurrently \"yarn:docs:test:*\"",
"docs:test:build": "cp test/*.js docs/test && tools/power",
"docs:test:copy": "cp browser/float16.js docs/test/float16.js && cp test/browser/*.html 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",
"lint": "concurrently \"yarn:lint:*\"",
"lint:eslint": "eslint src/**/*.mjs",
"lint:unused": "find-unused-exports --module-glob 'src/**/*.mjs'",
"prepublishOnly": "yarn run lint && yarn test",

@@ -78,11 +81,13 @@ "refresh": "yarn run clean && yarn run build && yarn run docs",

"babel-plugin-replace-import-extension": "^1.1.1",
"browserslist": "^4.17.4",
"eslint": "^8.0.1",
"browserslist": "^4.17.5",
"concurrently": "^6.3.0",
"eslint": "^8.1.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jsdoc": "^36.1.1",
"eslint-plugin-jsdoc": "^37.0.3",
"espower-cli": "^1.1.0",
"espower-loader": "^1.2.2",
"exorcist": "^2.0.0",
"http-server": "^13.0.2",
"mocha": "^9.1.2",
"find-unused-exports": "^2.0.0",
"http-server": "^14.0.0",
"mocha": "^9.1.3",
"nightwatch": "^1.7.11",

@@ -92,6 +97,6 @@ "nightwatch-saucelabs-endsauce": "^1.0.5",

"power-assert": "^1.4.2",
"rollup": "^2.58.0",
"rollup": "^2.58.3",
"source-map-support": "^0.5.20"
},
"packageManager": "yarn@1.22.11"
"packageManager": "yarn@1.22.15"
}

@@ -73,3 +73,4 @@ # <a href="https://git.io/float16">float16</a>

You can get modules from the [deno.land/x](https://deno.land/x/float16) hosting service.
You can get modules from the [deno.land/x](https://deno.land/x/float16) hosting
service.

@@ -86,3 +87,4 @@ ```ts

Deliver a `browser/float16.mjs` or `browser/float16.js` file in the npm package from your Web server with the JavaScript `Content-Type` HTTP header.
Deliver a `browser/float16.mjs` or `browser/float16.js` file in the npm package
from your Web server with the JavaScript `Content-Type` HTTP header.

@@ -137,2 +139,3 @@ ```html

```
</details>

@@ -142,3 +145,6 @@

**This package only uses up to ES2015 features** and does not use environment-dependent features (except for `inspect/`), so you can use it without any problems. It works fine with [the current officially supported versions of Node.js](https://github.com/nodejs/Release).
**This package only uses up to ES2015 features** and does not use
environment-dependent features (except for `inspect/`), so you can use it
without any problems. It works fine with
[the current officially supported versions of Node.js](https://github.com/nodejs/Release).

@@ -149,9 +155,11 @@ `Float16Array` implemented by the `Proxy`, so IE11 is never supported.

`lib/` and `browser/` directories in the npm package have JavaScript files already transpiled, and they have been tested automatically in the following environments:
`lib/` and `browser/` directories in the npm package have JavaScript files
already transpiled, and they have been tested automatically in the following
environments:
* Node.js: Active LTS
* Firefox: last 2 versions and ESR
* Chrome: last 2 versions
* Edge: last 2 versions
* Safari: last 2 versions
- Node.js: Active LTS
- Firefox: last 2 versions and ESR
- Chrome: last 2 versions
- Edge: last 2 versions
- Safari: last 2 versions

@@ -162,3 +170,4 @@ ## API

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

@@ -176,3 +185,4 @@ ```js

`isFloat16Array` is a utility function to check whether the value given as an argument is an instance of `Float16Array` or not.
`isFloat16Array` is a utility function to check whether the value given as an
argument is an instance of `Float16Array` or not.

@@ -191,3 +201,7 @@ ```ts

`getFloat16` and `setFloat16` 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)).
`getFloat16` and `setFloat16` 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)).

@@ -218,3 +232,4 @@ ```ts

`hfround` is similar to `Math.fround` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)).
`hfround` is similar to `Math.fround`
([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)).
This function returns nearest half precision float representation of a number.

@@ -238,7 +253,12 @@

Built-in `TypedArray` objects use "internal slots" for built-in methods. Some limitations exist because the `Proxy` object can't trap internal slots ([explanation](https://javascript.info/proxy#built-in-objects-internal-slots)).
Built-in `TypedArray` objects use "internal slots" for built-in methods. Some
limitations exist because the `Proxy` object can't trap internal slots
([explanation](https://javascript.info/proxy#built-in-objects-internal-slots)).
This package isn't polyfill, in other words, it doesn't change native global functions and static/prototype methods.
This package isn't polyfill, in other words, it doesn't change native global
functions and static/prototype methods.
E.g. `ArrayBuffer.isView` is the butlt-in method that checks if it has the `[[ViewedArrayBuffer]]` internal slot. It returns `false` for `Proxy` object such as `Float16Array` instance.
E.g. `ArrayBuffer.isView` is the butlt-in method that checks if it has the
`[[ViewedArrayBuffer]]` internal slot. It returns `false` for `Proxy` object
such as `Float16Array` instance.

@@ -252,5 +272,10 @@ ```js

The structured clone algorithm copies complex JavaScript objects. It is used internally when invoking `structuredClone()`, to transfer data between Web Workers via `postMessage()`, storing objects with IndexedDB, or copying objects for other APIs ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)).
The structured clone algorithm copies complex JavaScript objects. It is used
internally when invoking `structuredClone()`, to transfer data between Web
Workers via `postMessage()`, storing objects with IndexedDB, or copying objects
for other APIs
([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)).
It can't clone `Proxy` object such as `Float16Array` instance, you need to convert it to `Uint16Array` or deal with `ArrayBuffer` directly.
It can't clone `Proxy` object such as `Float16Array` instance, you need to
convert it to `Uint16Array` or deal with `ArrayBuffer` directly.

@@ -264,3 +289,6 @@ ```js

WebGL requires `Uint16Array` for buffer or texture data whose types are `gl.HALF_FLOAT` (WebGL 2) or `ext.HALF_FLOAT_OES` (WebGL 1 extension). Do not apply the `Float16Array` object directly to `gl.bufferData` or `gl.texImage2D` etc.
WebGL requires `Uint16Array` for buffer or texture data whose types are
`gl.HALF_FLOAT` (WebGL 2) or `ext.HALF_FLOAT_OES` (WebGL 1 extension). Do not
apply the `Float16Array` object directly to `gl.bufferData` or `gl.texImage2D`
etc.

@@ -288,3 +316,5 @@ ```js

See JSDoc comments in `src/Float16Array.mjs` for details. If you don't write hacky code, you shouldn't have any problems.
See JSDoc comments in `src/Float16Array.mjs` for details. If you don't write
hacky code, you shouldn't have any problems.
</details>

@@ -325,2 +355,3 @@

```
</details>

@@ -331,3 +362,3 @@

<details>
<summary>Manual build and test:</summary>
<summary>Manual build and test:</summary>

@@ -378,3 +409,6 @@ ### Manual build

You can access current [test page](https://petamoriken.github.io/float16/test) ([power-assert version](https://petamoriken.github.io/float16/test/power)) in `master` branch.
You can access current [test page](https://petamoriken.github.io/float16/test)
([power-assert version](https://petamoriken.github.io/float16/test/power)) in
`master` branch.
</details>

@@ -386,2 +420,5 @@

This software contains productions that are distributed under [the Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0). Specifically, `index.d.ts` is modified from the original [TypeScript lib files](https://github.com/microsoft/TypeScript/tree/main/src/lib).
This software contains productions that are distributed under
[the Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).
Specifically, `index.d.ts` is modified from the original
[TypeScript lib files](https://github.com/microsoft/TypeScript/tree/main/src/lib).

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

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