This commit is contained in:
86
node_modules/@petamoriken/float16/src/_util/arrayIterator.mjs
generated
vendored
Normal file
86
node_modules/@petamoriken/float16/src/_util/arrayIterator.mjs
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import {
|
||||
ArrayIteratorPrototype,
|
||||
ArrayIteratorPrototypeNext,
|
||||
ArrayPrototypeSymbolIterator,
|
||||
GeneratorPrototypeNext,
|
||||
IteratorPrototype,
|
||||
NativeArrayPrototypeSymbolIterator,
|
||||
NativeWeakMap,
|
||||
ObjectCreate,
|
||||
ObjectDefineProperty,
|
||||
ReflectGetOwnPropertyDescriptor,
|
||||
ReflectOwnKeys,
|
||||
SymbolIterator,
|
||||
WeakMapPrototypeGet,
|
||||
WeakMapPrototypeSet,
|
||||
} from "./primordials.mjs";
|
||||
|
||||
/** @type {WeakMap<{}, IterableIterator<any>>} */
|
||||
const arrayIterators = new NativeWeakMap();
|
||||
|
||||
const SafeIteratorPrototype = ObjectCreate(null, {
|
||||
next: {
|
||||
value: function next() {
|
||||
const arrayIterator = WeakMapPrototypeGet(arrayIterators, this);
|
||||
return ArrayIteratorPrototypeNext(arrayIterator);
|
||||
},
|
||||
},
|
||||
|
||||
[SymbolIterator]: {
|
||||
value: function values() {
|
||||
return this;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Wrap the Array around the SafeIterator If Array.prototype [@@iterator] has been modified
|
||||
* @type {<T>(array: T[]) => Iterable<T>}
|
||||
*/
|
||||
export function safeIfNeeded(array) {
|
||||
if (
|
||||
array[SymbolIterator] === NativeArrayPrototypeSymbolIterator &&
|
||||
ArrayIteratorPrototype.next === ArrayIteratorPrototypeNext
|
||||
) {
|
||||
return array;
|
||||
}
|
||||
|
||||
const safe = ObjectCreate(SafeIteratorPrototype);
|
||||
WeakMapPrototypeSet(arrayIterators, safe, ArrayPrototypeSymbolIterator(array));
|
||||
return safe;
|
||||
}
|
||||
|
||||
/** @type {WeakMap<{}, Generator<any>>} */
|
||||
const generators = new NativeWeakMap();
|
||||
|
||||
/** @see https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object */
|
||||
const DummyArrayIteratorPrototype = ObjectCreate(IteratorPrototype, {
|
||||
next: {
|
||||
value: function next() {
|
||||
const generator = WeakMapPrototypeGet(generators, this);
|
||||
return GeneratorPrototypeNext(generator);
|
||||
},
|
||||
writable: true,
|
||||
configurable: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (const key of ReflectOwnKeys(ArrayIteratorPrototype)) {
|
||||
// next method has already defined
|
||||
if (key === "next") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Copy ArrayIteratorPrototype descriptors to DummyArrayIteratorPrototype
|
||||
ObjectDefineProperty(DummyArrayIteratorPrototype, key, ReflectGetOwnPropertyDescriptor(ArrayIteratorPrototype, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the Generator around the dummy ArrayIterator
|
||||
* @type {<T>(generator: Generator<T>) => IterableIterator<T>}
|
||||
*/
|
||||
export function wrap(generator) {
|
||||
const dummy = ObjectCreate(DummyArrayIteratorPrototype);
|
||||
WeakMapPrototypeSet(generators, dummy, generator);
|
||||
return dummy;
|
||||
}
|
||||
31
node_modules/@petamoriken/float16/src/_util/brand.mjs
generated
vendored
Normal file
31
node_modules/@petamoriken/float16/src/_util/brand.mjs
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { isObject, isObjectLike } from "./is.mjs";
|
||||
import { THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT } from "./messages.mjs";
|
||||
import { NativeTypeError, ReflectGetPrototypeOf, ReflectHas, SymbolFor } from "./primordials.mjs";
|
||||
|
||||
export const brand = SymbolFor("__Float16Array__");
|
||||
|
||||
/**
|
||||
* @param {unknown} target
|
||||
* @throws {TypeError}
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function hasFloat16ArrayBrand(target) {
|
||||
if (!isObjectLike(target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const prototype = ReflectGetPrototypeOf(target);
|
||||
if (!isObjectLike(prototype)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const constructor = prototype.constructor;
|
||||
if (constructor === undefined) {
|
||||
return false;
|
||||
}
|
||||
if (!isObject(constructor)) {
|
||||
throw NativeTypeError(THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT);
|
||||
}
|
||||
|
||||
return ReflectHas(constructor, brand);
|
||||
}
|
||||
173
node_modules/@petamoriken/float16/src/_util/converter.mjs
generated
vendored
Normal file
173
node_modules/@petamoriken/float16/src/_util/converter.mjs
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
import {
|
||||
EPSILON,
|
||||
MathAbs,
|
||||
NativeArrayBuffer,
|
||||
NativeFloat32Array,
|
||||
NativeUint16Array,
|
||||
NativeUint32Array,
|
||||
NativeUint8Array,
|
||||
NumberIsFinite,
|
||||
NumberIsNaN,
|
||||
} from "./primordials.mjs";
|
||||
|
||||
const INVERSE_OF_EPSILON = 1 / EPSILON;
|
||||
|
||||
/**
|
||||
* rounds to the nearest value;
|
||||
* if the number falls midway, it is rounded to the nearest value with an even least significant digit
|
||||
* @param {number} num
|
||||
* @returns {number}
|
||||
*/
|
||||
function roundTiesToEven(num) {
|
||||
return (num + INVERSE_OF_EPSILON) - INVERSE_OF_EPSILON;
|
||||
}
|
||||
|
||||
const FLOAT16_MIN_VALUE = 6.103515625e-05;
|
||||
const FLOAT16_MAX_VALUE = 65504;
|
||||
const FLOAT16_EPSILON = 0.0009765625;
|
||||
|
||||
const FLOAT16_EPSILON_MULTIPLIED_BY_FLOAT16_MIN_VALUE = FLOAT16_EPSILON * FLOAT16_MIN_VALUE;
|
||||
const FLOAT16_EPSILON_DEVIDED_BY_EPSILON = FLOAT16_EPSILON * INVERSE_OF_EPSILON;
|
||||
|
||||
/**
|
||||
* round a number to a half float number
|
||||
* @param {unknown} num - double float
|
||||
* @returns {number} half float number
|
||||
*/
|
||||
export function roundToFloat16(num) {
|
||||
const number = +num;
|
||||
|
||||
// NaN, Infinity, -Infinity, 0, -0
|
||||
if (!NumberIsFinite(number) || number === 0) {
|
||||
return number;
|
||||
}
|
||||
|
||||
// finite except 0, -0
|
||||
const sign = number > 0 ? 1 : -1;
|
||||
const absolute = MathAbs(number);
|
||||
|
||||
// small number
|
||||
if (absolute < FLOAT16_MIN_VALUE) {
|
||||
return sign * roundTiesToEven(absolute / FLOAT16_EPSILON_MULTIPLIED_BY_FLOAT16_MIN_VALUE) * FLOAT16_EPSILON_MULTIPLIED_BY_FLOAT16_MIN_VALUE;
|
||||
}
|
||||
|
||||
const temp = (1 + FLOAT16_EPSILON_DEVIDED_BY_EPSILON) * absolute;
|
||||
const result = temp - (temp - absolute);
|
||||
|
||||
// large number
|
||||
if (result > FLOAT16_MAX_VALUE || NumberIsNaN(result)) {
|
||||
return sign * Infinity;
|
||||
}
|
||||
|
||||
return sign * result;
|
||||
}
|
||||
|
||||
// base algorithm: http://fox-toolkit.org/ftp/fasthalffloatconversion.pdf
|
||||
|
||||
const buffer = new NativeArrayBuffer(4);
|
||||
const floatView = new NativeFloat32Array(buffer);
|
||||
const uint32View = new NativeUint32Array(buffer);
|
||||
|
||||
const baseTable = new NativeUint16Array(512);
|
||||
const shiftTable = new NativeUint8Array(512);
|
||||
|
||||
for (let i = 0; i < 256; ++i) {
|
||||
const e = i - 127;
|
||||
|
||||
// very small number (0, -0)
|
||||
if (e < -24) {
|
||||
baseTable[i] = 0x0000;
|
||||
baseTable[i | 0x100] = 0x8000;
|
||||
shiftTable[i] = 24;
|
||||
shiftTable[i | 0x100] = 24;
|
||||
|
||||
// small number (denorm)
|
||||
} else if (e < -14) {
|
||||
baseTable[i] = 0x0400 >> (-e - 14);
|
||||
baseTable[i | 0x100] = (0x0400 >> (-e - 14)) | 0x8000;
|
||||
shiftTable[i] = -e - 1;
|
||||
shiftTable[i | 0x100] = -e - 1;
|
||||
|
||||
// normal number
|
||||
} else if (e <= 15) {
|
||||
baseTable[i] = (e + 15) << 10;
|
||||
baseTable[i | 0x100] = ((e + 15) << 10) | 0x8000;
|
||||
shiftTable[i] = 13;
|
||||
shiftTable[i | 0x100] = 13;
|
||||
|
||||
// large number (Infinity, -Infinity)
|
||||
} else if (e < 128) {
|
||||
baseTable[i] = 0x7c00;
|
||||
baseTable[i | 0x100] = 0xfc00;
|
||||
shiftTable[i] = 24;
|
||||
shiftTable[i | 0x100] = 24;
|
||||
|
||||
// stay (NaN, Infinity, -Infinity)
|
||||
} else {
|
||||
baseTable[i] = 0x7c00;
|
||||
baseTable[i | 0x100] = 0xfc00;
|
||||
shiftTable[i] = 13;
|
||||
shiftTable[i | 0x100] = 13;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* round a number to a half float number bits
|
||||
* @param {unknown} num - double float
|
||||
* @returns {number} half float number bits
|
||||
*/
|
||||
export function roundToFloat16Bits(num) {
|
||||
floatView[0] = roundToFloat16(num);
|
||||
const f = uint32View[0];
|
||||
const e = (f >> 23) & 0x1ff;
|
||||
return baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
|
||||
}
|
||||
|
||||
const mantissaTable = new NativeUint32Array(2048);
|
||||
for (let i = 1; i < 1024; ++i) {
|
||||
let m = i << 13; // zero pad mantissa bits
|
||||
let e = 0; // zero exponent
|
||||
|
||||
// normalized
|
||||
while ((m & 0x00800000) === 0) {
|
||||
m <<= 1;
|
||||
e -= 0x00800000; // decrement exponent
|
||||
}
|
||||
|
||||
m &= ~0x00800000; // clear leading 1 bit
|
||||
e += 0x38800000; // adjust bias
|
||||
|
||||
mantissaTable[i] = m | e;
|
||||
}
|
||||
for (let i = 1024; i < 2048; ++i) {
|
||||
mantissaTable[i] = 0x38000000 + ((i - 1024) << 13);
|
||||
}
|
||||
|
||||
const exponentTable = new NativeUint32Array(64);
|
||||
for (let i = 1; i < 31; ++i) {
|
||||
exponentTable[i] = i << 23;
|
||||
}
|
||||
exponentTable[31] = 0x47800000;
|
||||
exponentTable[32] = 0x80000000;
|
||||
for (let i = 33; i < 63; ++i) {
|
||||
exponentTable[i] = 0x80000000 + ((i - 32) << 23);
|
||||
}
|
||||
exponentTable[63] = 0xc7800000;
|
||||
|
||||
const offsetTable = new NativeUint16Array(64);
|
||||
for (let i = 1; i < 64; ++i) {
|
||||
if (i !== 32) {
|
||||
offsetTable[i] = 1024;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a half float number bits to a number
|
||||
* @param {number} float16bits - half float number bits
|
||||
* @returns {number} double float
|
||||
*/
|
||||
export function convertToNumber(float16bits) {
|
||||
const i = float16bits >> 10;
|
||||
uint32View[0] = mantissaTable[offsetTable[i] + (float16bits & 0x3ff)] + exponentTable[i];
|
||||
return floatView[0];
|
||||
}
|
||||
151
node_modules/@petamoriken/float16/src/_util/is.mjs
generated
vendored
Normal file
151
node_modules/@petamoriken/float16/src/_util/is.mjs
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
import {
|
||||
ArrayBufferPrototypeGetByteLength,
|
||||
ArrayIsArray,
|
||||
ArrayIteratorPrototype,
|
||||
ArrayIteratorPrototypeNext,
|
||||
MathTrunc,
|
||||
NativeArrayPrototypeSymbolIterator,
|
||||
NativeSharedArrayBuffer,
|
||||
NativeTypedArrayPrototypeSymbolIterator,
|
||||
NumberIsFinite,
|
||||
SharedArrayBufferPrototypeGetByteLength,
|
||||
SymbolIterator,
|
||||
TypedArrayPrototypeGetSymbolToStringTag,
|
||||
} from "./primordials.mjs";
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is {}}
|
||||
*/
|
||||
export function isObject(value) {
|
||||
return (
|
||||
(value !== null && typeof value === "object") ||
|
||||
typeof value === "function"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is {}}
|
||||
*/
|
||||
export function isObjectLike(value) {
|
||||
return value !== null && typeof value === "object";
|
||||
}
|
||||
|
||||
// Inspired by util.types implementation of Node.js
|
||||
/** @typedef {Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array} TypedArray */
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is TypedArray}
|
||||
*/
|
||||
export function isNativeTypedArray(value) {
|
||||
return TypedArrayPrototypeGetSymbolToStringTag(value) !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is BigInt64Array|BigUint64Array}
|
||||
*/
|
||||
export function isNativeBigIntTypedArray(value) {
|
||||
const typedArrayName = TypedArrayPrototypeGetSymbolToStringTag(value);
|
||||
return (
|
||||
typedArrayName === "BigInt64Array" ||
|
||||
typedArrayName === "BigUint64Array"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is ArrayBuffer}
|
||||
*/
|
||||
function isArrayBuffer(value) {
|
||||
try {
|
||||
// ArrayBuffers are never arrays
|
||||
if (ArrayIsArray(value)) {
|
||||
return false;
|
||||
}
|
||||
ArrayBufferPrototypeGetByteLength(/** @type {any} */ (value));
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is SharedArrayBuffer}
|
||||
*/
|
||||
export function isSharedArrayBuffer(value) {
|
||||
if (NativeSharedArrayBuffer === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
SharedArrayBufferPrototypeGetByteLength(/** @type {any} */ (value));
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is ArrayBuffer|SharedArrayBuffer}
|
||||
*/
|
||||
export function isAnyArrayBuffer(value) {
|
||||
return isArrayBuffer(value) || isSharedArrayBuffer(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is unknown[]}
|
||||
*/
|
||||
export function isOrdinaryArray(value) {
|
||||
if (!ArrayIsArray(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify that there are no changes in ArrayIterator
|
||||
return (
|
||||
value[SymbolIterator] === NativeArrayPrototypeSymbolIterator &&
|
||||
ArrayIteratorPrototype.next === ArrayIteratorPrototypeNext
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is TypedArray}
|
||||
*/
|
||||
export function isOrdinaryNativeTypedArray(value) {
|
||||
if (!isNativeTypedArray(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify that there are no changes in ArrayIterator
|
||||
return (
|
||||
value[SymbolIterator] === NativeTypedArrayPrototypeSymbolIterator &&
|
||||
ArrayIteratorPrototype.next === ArrayIteratorPrototypeNext
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @returns {value is string}
|
||||
*/
|
||||
export function isCanonicalIntegerIndexString(value) {
|
||||
if (typeof value !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const number = +value;
|
||||
if (value !== number + "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NumberIsFinite(number)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return number === MathTrunc(number);
|
||||
}
|
||||
22
node_modules/@petamoriken/float16/src/_util/messages.mjs
generated
vendored
Normal file
22
node_modules/@petamoriken/float16/src/_util/messages.mjs
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export const THIS_IS_NOT_AN_OBJECT = "This is not an object";
|
||||
export const THIS_IS_NOT_A_FLOAT16ARRAY_OBJECT = "This is not a Float16Array object";
|
||||
export const THIS_CONSTRUCTOR_IS_NOT_A_SUBCLASS_OF_FLOAT16ARRAY =
|
||||
"This constructor is not a subclass of Float16Array";
|
||||
export const THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT =
|
||||
"The constructor property value is not an object";
|
||||
export const SPECIES_CONSTRUCTOR_DIDNT_RETURN_TYPEDARRAY_OBJECT =
|
||||
"Species constructor didn't return TypedArray object";
|
||||
export const DERIVED_CONSTRUCTOR_CREATED_TYPEDARRAY_OBJECT_WHICH_WAS_TOO_SMALL_LENGTH =
|
||||
"Derived constructor created TypedArray object which was too small length";
|
||||
export const ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER =
|
||||
"Attempting to access detached ArrayBuffer";
|
||||
export const CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT =
|
||||
"Cannot convert undefined or null to object";
|
||||
export const CANNOT_MIX_BIGINT_AND_OTHER_TYPES =
|
||||
"Cannot mix BigInt and other types, use explicit conversions";
|
||||
export const ITERATOR_PROPERTY_IS_NOT_CALLABLE = "@@iterator property is not callable";
|
||||
export const REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE =
|
||||
"Reduce of empty array with no initial value";
|
||||
export const THE_COMPARISON_FUNCTION_MUST_BE_EITHER_A_FUNCTION_OR_UNDEFINED =
|
||||
"The comparison function must be either a function or undefined";
|
||||
export const OFFSET_IS_OUT_OF_BOUNDS = "Offset is out of bounds";
|
||||
254
node_modules/@petamoriken/float16/src/_util/primordials.mjs
generated
vendored
Normal file
254
node_modules/@petamoriken/float16/src/_util/primordials.mjs
generated
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
/* eslint-disable no-restricted-globals, no-restricted-syntax */
|
||||
/* global SharedArrayBuffer */
|
||||
|
||||
import { CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT } from "./messages.mjs";
|
||||
|
||||
/** @type {<T extends (...args: any) => any>(target: T) => (thisArg: ThisType<T>, ...args: any[]) => any} */
|
||||
function uncurryThis(target) {
|
||||
return (thisArg, ...args) => {
|
||||
return ReflectApply(target, thisArg, args);
|
||||
};
|
||||
}
|
||||
|
||||
/** @type {(target: any, key: string | symbol) => (thisArg: any, ...args: any[]) => any} */
|
||||
function uncurryThisGetter(target, key) {
|
||||
return uncurryThis(
|
||||
ReflectGetOwnPropertyDescriptor(
|
||||
target,
|
||||
key
|
||||
).get
|
||||
);
|
||||
}
|
||||
|
||||
// Reflect
|
||||
export const {
|
||||
apply: ReflectApply,
|
||||
construct: ReflectConstruct,
|
||||
defineProperty: ReflectDefineProperty,
|
||||
get: ReflectGet,
|
||||
getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
|
||||
getPrototypeOf: ReflectGetPrototypeOf,
|
||||
has: ReflectHas,
|
||||
ownKeys: ReflectOwnKeys,
|
||||
set: ReflectSet,
|
||||
setPrototypeOf: ReflectSetPrototypeOf,
|
||||
} = Reflect;
|
||||
|
||||
// Proxy
|
||||
export const NativeProxy = Proxy;
|
||||
|
||||
// Number
|
||||
export const {
|
||||
EPSILON,
|
||||
MAX_SAFE_INTEGER,
|
||||
isFinite: NumberIsFinite,
|
||||
isNaN: NumberIsNaN,
|
||||
} = Number;
|
||||
|
||||
// Symbol
|
||||
export const {
|
||||
iterator: SymbolIterator,
|
||||
species: SymbolSpecies,
|
||||
toStringTag: SymbolToStringTag,
|
||||
for: SymbolFor,
|
||||
} = Symbol;
|
||||
|
||||
// Object
|
||||
export const NativeObject = Object;
|
||||
export const {
|
||||
create: ObjectCreate,
|
||||
defineProperty: ObjectDefineProperty,
|
||||
freeze: ObjectFreeze,
|
||||
is: ObjectIs,
|
||||
} = NativeObject;
|
||||
const ObjectPrototype = NativeObject.prototype;
|
||||
/** @type {(object: object, key: PropertyKey) => Function | undefined} */
|
||||
export const ObjectPrototype__lookupGetter__ = /** @type {any} */ (ObjectPrototype).__lookupGetter__
|
||||
? uncurryThis(/** @type {any} */ (ObjectPrototype).__lookupGetter__)
|
||||
: (object, key) => {
|
||||
if (object == null) {
|
||||
throw NativeTypeError(
|
||||
CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT
|
||||
);
|
||||
}
|
||||
|
||||
let target = NativeObject(object);
|
||||
do {
|
||||
const descriptor = ReflectGetOwnPropertyDescriptor(target, key);
|
||||
if (descriptor !== undefined) {
|
||||
if (ObjectHasOwn(descriptor, "get")) {
|
||||
return descriptor.get;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} while ((target = ReflectGetPrototypeOf(target)) !== null);
|
||||
};
|
||||
/** @type {(object: object, key: PropertyKey) => boolean} */
|
||||
export const ObjectHasOwn = /** @type {any} */ (NativeObject).hasOwn ||
|
||||
uncurryThis(ObjectPrototype.hasOwnProperty);
|
||||
|
||||
// Array
|
||||
const NativeArray = Array;
|
||||
export const ArrayIsArray = NativeArray.isArray;
|
||||
const ArrayPrototype = NativeArray.prototype;
|
||||
/** @type {(array: ArrayLike<unknown>, separator?: string) => string} */
|
||||
export const ArrayPrototypeJoin = uncurryThis(ArrayPrototype.join);
|
||||
/** @type {<T>(array: T[], ...items: T[]) => number} */
|
||||
export const ArrayPrototypePush = uncurryThis(ArrayPrototype.push);
|
||||
/** @type {(array: ArrayLike<unknown>, ...opts: any[]) => string} */
|
||||
export const ArrayPrototypeToLocaleString = uncurryThis(
|
||||
ArrayPrototype.toLocaleString
|
||||
);
|
||||
export const NativeArrayPrototypeSymbolIterator = ArrayPrototype[SymbolIterator];
|
||||
/** @type {<T>(array: T[]) => IterableIterator<T>} */
|
||||
export const ArrayPrototypeSymbolIterator = uncurryThis(NativeArrayPrototypeSymbolIterator);
|
||||
|
||||
// Math
|
||||
export const {
|
||||
abs: MathAbs,
|
||||
trunc: MathTrunc,
|
||||
} = Math;
|
||||
|
||||
// ArrayBuffer
|
||||
export const NativeArrayBuffer = ArrayBuffer;
|
||||
export const ArrayBufferIsView = NativeArrayBuffer.isView;
|
||||
const ArrayBufferPrototype = NativeArrayBuffer.prototype;
|
||||
/** @type {(buffer: ArrayBuffer, begin?: number, end?: number) => number} */
|
||||
export const ArrayBufferPrototypeSlice = uncurryThis(ArrayBufferPrototype.slice);
|
||||
/** @type {(buffer: ArrayBuffer) => ArrayBuffer} */
|
||||
export const ArrayBufferPrototypeGetByteLength = uncurryThisGetter(ArrayBufferPrototype, "byteLength");
|
||||
|
||||
// SharedArrayBuffer
|
||||
export const NativeSharedArrayBuffer = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : null;
|
||||
/** @type {(buffer: SharedArrayBuffer) => SharedArrayBuffer} */
|
||||
export const SharedArrayBufferPrototypeGetByteLength = NativeSharedArrayBuffer
|
||||
&& uncurryThisGetter(NativeSharedArrayBuffer.prototype, "byteLength");
|
||||
|
||||
// TypedArray
|
||||
/** @typedef {Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array} TypedArray */
|
||||
/** @type {any} */
|
||||
export const TypedArray = ReflectGetPrototypeOf(Uint8Array);
|
||||
const TypedArrayFrom = TypedArray.from;
|
||||
export const TypedArrayPrototype = TypedArray.prototype;
|
||||
export const NativeTypedArrayPrototypeSymbolIterator = TypedArrayPrototype[SymbolIterator];
|
||||
/** @type {(typedArray: TypedArray) => IterableIterator<number>} */
|
||||
export const TypedArrayPrototypeKeys = uncurryThis(TypedArrayPrototype.keys);
|
||||
/** @type {(typedArray: TypedArray) => IterableIterator<number>} */
|
||||
export const TypedArrayPrototypeValues = uncurryThis(
|
||||
TypedArrayPrototype.values
|
||||
);
|
||||
/** @type {(typedArray: TypedArray) => IterableIterator<[number, number]>} */
|
||||
export const TypedArrayPrototypeEntries = uncurryThis(
|
||||
TypedArrayPrototype.entries
|
||||
);
|
||||
/** @type {(typedArray: TypedArray, array: ArrayLike<number>, offset?: number) => void} */
|
||||
export const TypedArrayPrototypeSet = uncurryThis(TypedArrayPrototype.set);
|
||||
/** @type {<T extends TypedArray>(typedArray: T) => T} */
|
||||
export const TypedArrayPrototypeReverse = uncurryThis(
|
||||
TypedArrayPrototype.reverse
|
||||
);
|
||||
/** @type {<T extends TypedArray>(typedArray: T, value: number, start?: number, end?: number) => T} */
|
||||
export const TypedArrayPrototypeFill = uncurryThis(TypedArrayPrototype.fill);
|
||||
/** @type {<T extends TypedArray>(typedArray: T, target: number, start: number, end?: number) => T} */
|
||||
export const TypedArrayPrototypeCopyWithin = uncurryThis(
|
||||
TypedArrayPrototype.copyWithin
|
||||
);
|
||||
/** @type {<T extends TypedArray>(typedArray: T, compareFn?: (a: number, b: number) => number) => T} */
|
||||
export const TypedArrayPrototypeSort = uncurryThis(TypedArrayPrototype.sort);
|
||||
/** @type {<T extends TypedArray>(typedArray: T, start?: number, end?: number) => T} */
|
||||
export const TypedArrayPrototypeSlice = uncurryThis(TypedArrayPrototype.slice);
|
||||
/** @type {<T extends TypedArray>(typedArray: T, start?: number, end?: number) => T} */
|
||||
export const TypedArrayPrototypeSubarray = uncurryThis(
|
||||
TypedArrayPrototype.subarray
|
||||
);
|
||||
/** @type {((typedArray: TypedArray) => ArrayBuffer)} */
|
||||
export const TypedArrayPrototypeGetBuffer = uncurryThisGetter(
|
||||
TypedArrayPrototype,
|
||||
"buffer"
|
||||
);
|
||||
/** @type {((typedArray: TypedArray) => number)} */
|
||||
export const TypedArrayPrototypeGetByteOffset = uncurryThisGetter(
|
||||
TypedArrayPrototype,
|
||||
"byteOffset"
|
||||
);
|
||||
/** @type {((typedArray: TypedArray) => number)} */
|
||||
export const TypedArrayPrototypeGetLength = uncurryThisGetter(
|
||||
TypedArrayPrototype,
|
||||
"length"
|
||||
);
|
||||
/** @type {(target: unknown) => string} */
|
||||
export const TypedArrayPrototypeGetSymbolToStringTag = uncurryThisGetter(
|
||||
TypedArrayPrototype,
|
||||
SymbolToStringTag
|
||||
);
|
||||
|
||||
// Uint8Array
|
||||
export const NativeUint8Array = Uint8Array;
|
||||
|
||||
// Uint16Array
|
||||
export const NativeUint16Array = Uint16Array;
|
||||
/** @type {Uint16ArrayConstructor["from"]} */
|
||||
export const Uint16ArrayFrom = (...args) => {
|
||||
return ReflectApply(TypedArrayFrom, NativeUint16Array, args);
|
||||
};
|
||||
|
||||
// Uint32Array
|
||||
export const NativeUint32Array = Uint32Array;
|
||||
|
||||
// Float32Array
|
||||
export const NativeFloat32Array = Float32Array;
|
||||
|
||||
// ArrayIterator
|
||||
/** @type {any} */
|
||||
export const ArrayIteratorPrototype = ReflectGetPrototypeOf([][SymbolIterator]());
|
||||
/** @type {<T>(arrayIterator: IterableIterator<T>) => IteratorResult<T>} */
|
||||
export const ArrayIteratorPrototypeNext = uncurryThis(ArrayIteratorPrototype.next);
|
||||
|
||||
// Generator
|
||||
/** @type {<T = unknown, TReturn = any, TNext = unknown>(generator: Generator<T, TReturn, TNext>, value?: TNext) => T} */
|
||||
export const GeneratorPrototypeNext = uncurryThis((function* () {})().next);
|
||||
|
||||
// Iterator
|
||||
export const IteratorPrototype = ReflectGetPrototypeOf(ArrayIteratorPrototype);
|
||||
|
||||
// DataView
|
||||
const DataViewPrototype = DataView.prototype;
|
||||
/** @type {(dataView: DataView, byteOffset: number, littleEndian?: boolean) => number} */
|
||||
export const DataViewPrototypeGetUint16 = uncurryThis(
|
||||
DataViewPrototype.getUint16
|
||||
);
|
||||
/** @type {(dataView: DataView, byteOffset: number, value: number, littleEndian?: boolean) => void} */
|
||||
export const DataViewPrototypeSetUint16 = uncurryThis(
|
||||
DataViewPrototype.setUint16
|
||||
);
|
||||
|
||||
// Error
|
||||
export const NativeTypeError = TypeError;
|
||||
export const NativeRangeError = RangeError;
|
||||
|
||||
// WeakSet
|
||||
/**
|
||||
* Do not construct with arguments to avoid calling the "add" method
|
||||
* @type {{new <T extends {}>(): WeakSet<T>}}
|
||||
*/
|
||||
export const NativeWeakSet = WeakSet;
|
||||
const WeakSetPrototype = NativeWeakSet.prototype;
|
||||
/** @type {<T extends {}>(set: WeakSet<T>, value: T) => Set<T>} */
|
||||
export const WeakSetPrototypeAdd = uncurryThis(WeakSetPrototype.add);
|
||||
/** @type {<T extends {}>(set: WeakSet<T>, value: T) => boolean} */
|
||||
export const WeakSetPrototypeHas = uncurryThis(WeakSetPrototype.has);
|
||||
|
||||
// WeakMap
|
||||
/**
|
||||
* Do not construct with arguments to avoid calling the "set" method
|
||||
* @type {{new <K extends {}, V>(): WeakMap<K, V>}}
|
||||
*/
|
||||
export const NativeWeakMap = WeakMap;
|
||||
const WeakMapPrototype = NativeWeakMap.prototype;
|
||||
/** @type {<K extends {}, V>(weakMap: WeakMap<K, V>, key: K) => V} */
|
||||
export const WeakMapPrototypeGet = uncurryThis(WeakMapPrototype.get);
|
||||
/** @type {<K extends {}, V>(weakMap: WeakMap<K, V>, key: K) => boolean} */
|
||||
export const WeakMapPrototypeHas = uncurryThis(WeakMapPrototype.has);
|
||||
/** @type {<K extends {}, V>(weakMap: WeakMap<K, V>, key: K, value: V) => WeakMap} */
|
||||
export const WeakMapPrototypeSet = uncurryThis(WeakMapPrototype.set);
|
||||
137
node_modules/@petamoriken/float16/src/_util/spec.mjs
generated
vendored
Normal file
137
node_modules/@petamoriken/float16/src/_util/spec.mjs
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
import { isObject, isSharedArrayBuffer } from "./is.mjs";
|
||||
import {
|
||||
THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT,
|
||||
THIS_IS_NOT_AN_OBJECT,
|
||||
} from "./messages.mjs";
|
||||
import {
|
||||
ArrayBufferPrototypeSlice,
|
||||
MAX_SAFE_INTEGER,
|
||||
MathTrunc,
|
||||
NativeTypeError,
|
||||
NumberIsNaN,
|
||||
ObjectIs,
|
||||
SymbolSpecies,
|
||||
} from "./primordials.mjs";
|
||||
|
||||
/**
|
||||
* @see https://tc39.es/ecma262/#sec-tointegerorinfinity
|
||||
* @param {unknown} target
|
||||
* @returns {number}
|
||||
*/
|
||||
export function ToIntegerOrInfinity(target) {
|
||||
const number = +target;
|
||||
|
||||
if (NumberIsNaN(number) || number === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return MathTrunc(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tc39.es/ecma262/#sec-tolength
|
||||
* @param {unknown} target
|
||||
* @returns {number}
|
||||
*/
|
||||
export function ToLength(target) {
|
||||
const length = ToIntegerOrInfinity(target);
|
||||
if (length < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return length < MAX_SAFE_INTEGER
|
||||
? length
|
||||
: MAX_SAFE_INTEGER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tc39.es/ecma262/#sec-speciesconstructor
|
||||
* @param {object} target
|
||||
* @param {{ new(...args: any[]): any; }} defaultConstructor
|
||||
* @returns {{ new(...args: any[]): any; }}
|
||||
*/
|
||||
export function SpeciesConstructor(target, defaultConstructor) {
|
||||
if (!isObject(target)) {
|
||||
throw NativeTypeError(THIS_IS_NOT_AN_OBJECT);
|
||||
}
|
||||
|
||||
const constructor = target.constructor;
|
||||
if (constructor === undefined) {
|
||||
return defaultConstructor;
|
||||
}
|
||||
if (!isObject(constructor)) {
|
||||
throw NativeTypeError(THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT);
|
||||
}
|
||||
|
||||
const species = constructor[SymbolSpecies];
|
||||
if (species == null) {
|
||||
return defaultConstructor;
|
||||
}
|
||||
|
||||
return species;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://tc39.es/ecma262/#sec-isdetachedbuffer
|
||||
* @param {ArrayBufferLike} buffer
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function IsDetachedBuffer(buffer) {
|
||||
if (isSharedArrayBuffer(buffer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
ArrayBufferPrototypeSlice(buffer, 0, 0);
|
||||
return false;
|
||||
} catch (e) {/* empty */}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* bigint comparisons are not supported
|
||||
* @see https://tc39.es/ecma262/#sec-%typedarray%.prototype.sort
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @returns {-1 | 0 | 1}
|
||||
*/
|
||||
export function defaultCompare(x, y) {
|
||||
const isXNaN = NumberIsNaN(x);
|
||||
const isYNaN = NumberIsNaN(y);
|
||||
|
||||
if (isXNaN && isYNaN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (isXNaN) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (isYNaN) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x < y) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x > y) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x === 0 && y === 0) {
|
||||
const isXPlusZero = ObjectIs(x, 0);
|
||||
const isYPlusZero = ObjectIs(y, 0);
|
||||
|
||||
if (!isXPlusZero && isYPlusZero) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isXPlusZero && !isYPlusZero) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user