This commit is contained in:
21
node_modules/@petamoriken/float16/LICENSE
generated
vendored
Normal file
21
node_modules/@petamoriken/float16/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2024 Kenta Moriuchi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
412
node_modules/@petamoriken/float16/README.md
generated
vendored
Normal file
412
node_modules/@petamoriken/float16/README.md
generated
vendored
Normal file
@@ -0,0 +1,412 @@
|
||||
# <a href="https://github.com/petamoriken/float16">float16</a>
|
||||
|
||||
<p align="center">
|
||||
IEEE 754 half-precision floating-point ponyfill for JavaScript<br>
|
||||
See <a href="https://github.com/tc39/proposal-float16array">TC39 proposal</a> or <a href="https://esdiscuss.org/topic/float16array">the archive of the ES Discuss Float16Array topic</a> for details
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/package/@petamoriken/float16"><img src="https://img.shields.io/npm/dw/@petamoriken/float16?logo=npm&style=flat-square" alt="npm downloads"></a>
|
||||
<a href="https://www.npmjs.com/package/@petamoriken/float16"><img src="https://img.shields.io/npm/v/@petamoriken/float16.svg?label=version&logo=npm&style=flat-square" alt="npm version"></a>
|
||||
<a href="https://jsr.io/@petamoriken/float16"><img src="https://jsr.io/badges/@petamoriken/float16?label=version&style=flat-square" alt="jsr version"></a>
|
||||
<br>
|
||||
<a href="https://github.com/petamoriken/float16/blob/master/package.json"><img src="https://img.shields.io/badge/dependencies-none-brightgreen?style=flat-square" alt="dependencies"></a>
|
||||
<a href="https://github.com/petamoriken/float16/blob/master/LICENSE"><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"><img src="https://img.shields.io/codecov/c/gh/petamoriken/float16?logo=codecov&style=flat-square" alt="codecov"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://saucelabs.com/u/petamoriken">
|
||||
<img src="https://app.saucelabs.com/browser-matrix/petamoriken.svg" alt="Sauce Labs browser matrix">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## Install
|
||||
|
||||
### Node.js
|
||||
|
||||
```console
|
||||
npm install @petamoriken/float16
|
||||
```
|
||||
|
||||
### Deno
|
||||
|
||||
> [!NOTE]
|
||||
> `Float16Array`, `DataView` methods for reading and setting float16 values, and `Math.f16round` are supported since Deno v1.43.
|
||||
|
||||
```console
|
||||
deno add @petamoriken/float16
|
||||
```
|
||||
|
||||
### Bun
|
||||
|
||||
```console
|
||||
bun add @petamoriken/float16
|
||||
```
|
||||
|
||||
## Import
|
||||
|
||||
### Node.js, Deno, Bun or Bundler
|
||||
|
||||
```js
|
||||
import {
|
||||
Float16Array, isFloat16Array, isTypedArray,
|
||||
getFloat16, setFloat16,
|
||||
f16round,
|
||||
} from "@petamoriken/float16";
|
||||
```
|
||||
|
||||
### Browser
|
||||
|
||||
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.
|
||||
|
||||
```html
|
||||
<!-- Module Scripts -->
|
||||
<script type="module">
|
||||
import {
|
||||
Float16Array, isFloat16Array, isTypedArray,
|
||||
getFloat16, setFloat16,
|
||||
f16round,
|
||||
} from "DEST/TO/float16.mjs";
|
||||
</script>
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- Classic Scripts -->
|
||||
<script src="DEST/TO/float16.js"></script>
|
||||
<script>
|
||||
const {
|
||||
Float16Array, isFloat16Array, isTypedArray,
|
||||
getFloat16, setFloat16,
|
||||
f16round,
|
||||
} = float16;
|
||||
</script>
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Or, you can use <a href="https://www.jsdelivr.com/package/npm/@petamoriken/float16">jsDelivr CDN</a>.</summary>
|
||||
|
||||
```html
|
||||
<!-- Module Scripts -->
|
||||
<script type="module">
|
||||
import {
|
||||
Float16Array, isFloat16Array, isTypedArray,
|
||||
getFloat16, setFloat16,
|
||||
f16round,
|
||||
} from "https://cdn.jsdelivr.net/npm/@petamoriken/float16/+esm";
|
||||
</script>
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- Classic Scripts -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/@petamoriken/float16/browser/float16.min.js"></script>
|
||||
<script>
|
||||
const {
|
||||
Float16Array, isFloat16Array, isTypedArray,
|
||||
getFloat16, setFloat16,
|
||||
f16round,
|
||||
} = float16;
|
||||
</script>
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## Support engines
|
||||
|
||||
**This package only requires 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).
|
||||
|
||||
`Float16Array` implemented by `Proxy` and `Reflect`, so IE11 is never supported
|
||||
even if you use polyfills.
|
||||
|
||||
### Pre-transpiled JavaScript files (CommonJS, IIFE)
|
||||
|
||||
`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
|
||||
- Safari: last 2 versions
|
||||
|
||||
## API
|
||||
|
||||
### `Float16Array`
|
||||
|
||||
`Float16Array` is similar to `TypedArray` such as `Float32Array`
|
||||
([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)).
|
||||
|
||||
```js
|
||||
const array = new Float16Array([1.0, 1.1, 1.2, 1.3]);
|
||||
for (const value of array) {
|
||||
// 1, 1.099609375, 1.2001953125, 1.2998046875
|
||||
console.log(value);
|
||||
}
|
||||
|
||||
// Float16Array(4) [ 2, 2.19921875, 2.3984375, 2.599609375 ]
|
||||
array.map((value) => value * 2);
|
||||
```
|
||||
|
||||
### `isFloat16Array`
|
||||
|
||||
> [!WARNING]
|
||||
> This API returns `false` for ECMAScript's native `Float16Array`
|
||||
|
||||
`isFloat16Array` is a utility function to check whether the value given as an
|
||||
argument is an instance of `Float16Array` or not.
|
||||
|
||||
```js
|
||||
const buffer = new ArrayBuffer(256);
|
||||
|
||||
// true
|
||||
isFloat16Array(new Float16Array(buffer));
|
||||
|
||||
// false
|
||||
isFloat16Array(new Float32Array(buffer));
|
||||
isFloat16Array(new Uint16Array(buffer));
|
||||
isFloat16Array(new DataView(buffer));
|
||||
```
|
||||
|
||||
### `isTypedArray`
|
||||
|
||||
`isTypedArray` is a utility function to check whether the value given as an
|
||||
argument is an instance of a type of `TypedArray` or not. Unlike
|
||||
`util.types.isTypedArray` in Node.js, this returns `true` for `Float16Array`.
|
||||
|
||||
```js
|
||||
const buffer = new ArrayBuffer(256);
|
||||
|
||||
// true
|
||||
isTypedArray(new Float16Array(buffer));
|
||||
isTypedArray(new Float32Array(buffer));
|
||||
isTypedArray(new Uint16Array(buffer));
|
||||
|
||||
// false
|
||||
isTypedArray(new DataView(buffer));
|
||||
```
|
||||
|
||||
### `getFloat16`, `setFloat16`
|
||||
|
||||
`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)).
|
||||
|
||||
```ts
|
||||
declare function getFloat16(view: DataView, byteOffset: number, littleEndian?: boolean): number;
|
||||
declare function setFloat16(view: DataView, byteOffset: number, value: number, littleEndian?: boolean): void;
|
||||
```
|
||||
|
||||
```js
|
||||
const buffer = new ArrayBuffer(256);
|
||||
const view = new DataView(buffer);
|
||||
|
||||
view.setUint16(0, 0x1234);
|
||||
getFloat16(view, 0); // 0.0007572174072265625
|
||||
|
||||
// You can append methods to DataView instance
|
||||
view.getFloat16 = (...args) => getFloat16(view, ...args);
|
||||
view.setFloat16 = (...args) => setFloat16(view, ...args);
|
||||
|
||||
view.getFloat16(0); // 0.0007572174072265625
|
||||
|
||||
view.setFloat16(0, Math.PI, true);
|
||||
view.getFloat16(0, true); // 3.140625
|
||||
```
|
||||
|
||||
### `f16round` (alias: `hfround`)
|
||||
|
||||
`f16round` 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.
|
||||
|
||||
```ts
|
||||
declare function f16round(x: number): number;
|
||||
```
|
||||
|
||||
```js
|
||||
Math.fround(1.337); // 1.3370000123977661
|
||||
f16round(1.337); // 1.3369140625
|
||||
```
|
||||
|
||||
## `Float16Array` limitations (edge cases)
|
||||
|
||||
<details>
|
||||
<summary><code>Float16Array</code> has some limitations, because it is impossible to completely reproduce the behavior of <code>TypedArray</code>. Be careful when checking if it is a <code>TypedArray</code> or not by using <code>ArrayBuffer.isView</code>, and when using Web standards such as <code>structuredClone</code> and WebGL.</summary>
|
||||
|
||||
### Built-in functions
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
ArrayBuffer.isView(new Float32Array(10)); // true
|
||||
ArrayBuffer.isView(new Float16Array(10)); // false
|
||||
```
|
||||
|
||||
### The structured clone algorithm (Web Workers, IndexedDB, etc)
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
const array = new Float16Array([1.0, 1.1, 1.2]);
|
||||
const cloned = structuredClone({ buffer: array.buffer });
|
||||
```
|
||||
|
||||
### WebGL
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
// WebGL 2 example
|
||||
const vertices = new Float16Array([
|
||||
-0.5, -0.5, 0,
|
||||
0.5, -0.5, 0,
|
||||
0.5, 0.5, 0,
|
||||
]);
|
||||
|
||||
const buffer = gl.createBuffer();
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
||||
|
||||
// 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);
|
||||
```
|
||||
|
||||
### Others
|
||||
|
||||
See JSDoc comments in `src/Float16Array.mjs` for details. If you don't write
|
||||
hacky code, you shouldn't have any problems.
|
||||
|
||||
</details>
|
||||
|
||||
## `Float16Array` custom inspection
|
||||
|
||||
<details>
|
||||
<summary>Provides custom inspection for Node.js and Deno, which makes the results of <code>console.log</code> more readable.
|
||||
</summary>
|
||||
|
||||
### Node.js
|
||||
|
||||
```js
|
||||
import { Float16Array } from "@petamoriken/float16";
|
||||
import { customInspect } from "@petamoriken/float16/inspect";
|
||||
|
||||
Float16Array.prototype[Symbol.for("nodejs.util.inspect.custom")] = customInspect;
|
||||
```
|
||||
|
||||
### Deno
|
||||
|
||||
```ts
|
||||
import { Float16Array } from "https://deno.land/x/float16/mod.ts";
|
||||
import { customInspect } from "https://deno.land/x/float16/inspect.ts";
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
(Float16Array.prototype as any)[Symbol.for("Deno.customInspect")] = customInspect;
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## Development
|
||||
|
||||
<details>
|
||||
<summary>Manual build and test</summary>
|
||||
|
||||
### Manual build
|
||||
|
||||
This repository uses corepack for package manager manager.
|
||||
You may have to activate yarn in corepack.
|
||||
|
||||
```console
|
||||
corepack enable yarn
|
||||
```
|
||||
|
||||
Download devDependencies.
|
||||
|
||||
```console
|
||||
yarn
|
||||
```
|
||||
|
||||
Build `lib/`, `browser/` files.
|
||||
|
||||
```console
|
||||
yarn run build
|
||||
```
|
||||
|
||||
Build `docs/` files (for browser test).
|
||||
|
||||
```console
|
||||
yarn run docs
|
||||
```
|
||||
|
||||
### Test
|
||||
|
||||
This repository uses corepack for package manager manager.
|
||||
You may have to activate yarn in corepack.
|
||||
|
||||
```console
|
||||
corepack enable yarn
|
||||
```
|
||||
|
||||
Download devDependencies.
|
||||
|
||||
```console
|
||||
yarn
|
||||
```
|
||||
|
||||
#### Node.js test
|
||||
|
||||
```console
|
||||
NODE_ENV=test yarn build:lib
|
||||
yarn test
|
||||
```
|
||||
|
||||
#### Browser test
|
||||
|
||||
```console
|
||||
NODE_ENV=test yarn build:browser
|
||||
yarn docs
|
||||
```
|
||||
|
||||
Access `docs/test/index.html` with browsers.
|
||||
|
||||
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>
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
|
||||
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).
|
||||
1340
node_modules/@petamoriken/float16/browser/float16.js
generated
vendored
Normal file
1340
node_modules/@petamoriken/float16/browser/float16.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1325
node_modules/@petamoriken/float16/browser/float16.mjs
generated
vendored
Normal file
1325
node_modules/@petamoriken/float16/browser/float16.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
498
node_modules/@petamoriken/float16/index.d.ts
generated
vendored
Normal file
498
node_modules/@petamoriken/float16/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,498 @@
|
||||
/**
|
||||
* A typed array of 16-bit float values. The contents are initialized to 0. If the requested number
|
||||
* of bytes could not be allocated an exception is raised.
|
||||
*/
|
||||
export interface Float16Array {
|
||||
/**
|
||||
* The size in bytes of each element in the array.
|
||||
*/
|
||||
readonly BYTES_PER_ELEMENT: number;
|
||||
|
||||
/**
|
||||
* The ArrayBuffer instance referenced by the array.
|
||||
*/
|
||||
readonly buffer: ArrayBufferLike;
|
||||
|
||||
/**
|
||||
* The length in bytes of the array.
|
||||
*/
|
||||
readonly byteLength: number;
|
||||
|
||||
/**
|
||||
* The offset in bytes of the array.
|
||||
*/
|
||||
readonly byteOffset: number;
|
||||
|
||||
[Symbol.iterator](): IterableIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns the item located at the specified index.
|
||||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
|
||||
*/
|
||||
at(index: number): number | undefined;
|
||||
|
||||
/**
|
||||
* Returns the this object after copying a section of the array identified by start and end
|
||||
* to the same array starting at position target
|
||||
* @param target If target is negative, it is treated as length+target where length is the
|
||||
* length of the array.
|
||||
* @param start If start is negative, it is treated as length+start. If end is negative, it
|
||||
* is treated as length+end.
|
||||
* @param end If not specified, length of the this object is used as its default value.
|
||||
*/
|
||||
copyWithin(target: number, start: number, end?: number): this;
|
||||
|
||||
/**
|
||||
* Determines whether all the members of an array satisfy the specified test.
|
||||
* @param callbackfn A function that accepts up to three arguments. The every method calls
|
||||
* the callbackfn function for each element in the array until the callbackfn returns a value
|
||||
* which is coercible to the Boolean value false, or until the end of the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
|
||||
* If thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
every(
|
||||
callbackfn: (value: number, index: number, array: Float16Array) => unknown,
|
||||
thisArg?: any,
|
||||
): boolean;
|
||||
|
||||
/**
|
||||
* Returns the this object after filling the section identified by start and end with value
|
||||
* @param value value to fill array section with
|
||||
* @param start index to start filling the array at. If start is negative, it is treated as
|
||||
* length+start where length is the length of the array.
|
||||
* @param end index to stop filling the array at. If end is negative, it is treated as
|
||||
* length+end.
|
||||
*/
|
||||
fill(value: number, start?: number, end?: number): this;
|
||||
|
||||
/**
|
||||
* Returns the elements of an array that meet the condition specified in a callback function.
|
||||
* @param predicate A function that accepts up to three arguments. The filter method calls
|
||||
* the predicate function one time for each element in the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the predicate function.
|
||||
* If thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
filter(
|
||||
predicate: (value: number, index: number, array: Float16Array) => any,
|
||||
thisArg?: any,
|
||||
): Float16Array;
|
||||
|
||||
/**
|
||||
* Returns the value of the first element in the array where predicate is true, and undefined
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in ascending
|
||||
* order, until it finds one where predicate returns true. If such an element is found, find
|
||||
* immediately returns that element value. Otherwise, find returns undefined.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
find(
|
||||
predicate: (value: number, index: number, obj: Float16Array) => boolean,
|
||||
thisArg?: any,
|
||||
): number | undefined;
|
||||
|
||||
/**
|
||||
* Returns the index of the first element in the array where predicate is true, and -1
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in ascending
|
||||
* order, until it finds one where predicate returns true. If such an element is found,
|
||||
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
findIndex(
|
||||
predicate: (value: number, index: number, obj: Float16Array) => boolean,
|
||||
thisArg?: any,
|
||||
): number;
|
||||
|
||||
/**
|
||||
* Returns the value of the last element in the array where predicate is true, and undefined
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in descending
|
||||
* order, until it finds one where predicate returns true. If such an element is found, findLast
|
||||
* immediately returns that element value. Otherwise, findLast returns undefined.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
findLast(
|
||||
predicate: (value: number, index: number, obj: Float16Array) => boolean,
|
||||
thisArg?: any,
|
||||
): number | undefined;
|
||||
|
||||
/**
|
||||
* Returns the index of the last element in the array where predicate is true, and -1
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in descending
|
||||
* order, until it finds one where predicate returns true. If such an element is found,
|
||||
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
findLastIndex(
|
||||
predicate: (value: number, index: number, obj: Float16Array) => boolean,
|
||||
thisArg?: any,
|
||||
): number;
|
||||
|
||||
/**
|
||||
* Performs the specified action for each element in an array.
|
||||
* @param callbackfn A function that accepts up to three arguments. forEach calls the
|
||||
* callbackfn function one time for each element in the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
|
||||
* If thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
forEach(
|
||||
callbackfn: (value: number, index: number, array: Float16Array) => void,
|
||||
thisArg?: any,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns the index of the first occurrence of a value in an array.
|
||||
* @param searchElement The value to locate in the array.
|
||||
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
|
||||
* search starts at index 0.
|
||||
*/
|
||||
indexOf(searchElement: number, fromIndex?: number): number;
|
||||
|
||||
/**
|
||||
* Adds all the elements of an array separated by the specified separator string.
|
||||
* @param separator A string used to separate one element of an array from the next in the
|
||||
* resulting String. If omitted, the array elements are separated with a comma.
|
||||
*/
|
||||
join(separator?: string): string;
|
||||
|
||||
/**
|
||||
* Returns the index of the last occurrence of a value in an array.
|
||||
* @param searchElement The value to locate in the array.
|
||||
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
|
||||
* search starts at index 0.
|
||||
*/
|
||||
lastIndexOf(searchElement: number, fromIndex?: number): number;
|
||||
|
||||
/**
|
||||
* The length of the array.
|
||||
*/
|
||||
readonly length: number;
|
||||
|
||||
/**
|
||||
* Calls a defined callback function on each element of an array, and returns an array that
|
||||
* contains the results.
|
||||
* @param callbackfn A function that accepts up to three arguments. The map method calls the
|
||||
* callbackfn function one time for each element in the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
|
||||
* If thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
map(
|
||||
callbackfn: (value: number, index: number, array: Float16Array) => number,
|
||||
thisArg?: any,
|
||||
): Float16Array;
|
||||
|
||||
/**
|
||||
* Calls the specified callback function for all the elements in an array. The return value of
|
||||
* the callback function is the accumulated result, and is provided as an argument in the next
|
||||
* call to the callback function.
|
||||
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the
|
||||
* callbackfn function one time for each element in the array.
|
||||
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
||||
* the accumulation. The first call to the callbackfn function provides this value as an argument
|
||||
* instead of an array value.
|
||||
*/
|
||||
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<U>(
|
||||
callbackfn: (
|
||||
previousValue: U,
|
||||
currentValue: number,
|
||||
currentIndex: number,
|
||||
array: Float16Array,
|
||||
) => U,
|
||||
initialValue: U,
|
||||
): U;
|
||||
|
||||
/**
|
||||
* Calls the specified callback function for all the elements in an array, in descending order.
|
||||
* The return value of the callback function is the accumulated result, and is provided as an
|
||||
* argument in the next call to the callback function.
|
||||
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
|
||||
* the callbackfn function one time for each element in the array.
|
||||
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
||||
* the accumulation. The first call to the callbackfn function provides this value as an
|
||||
* argument instead of an array value.
|
||||
*/
|
||||
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<U>(
|
||||
callbackfn: (
|
||||
previousValue: U,
|
||||
currentValue: number,
|
||||
currentIndex: number,
|
||||
array: Float16Array,
|
||||
) => U,
|
||||
initialValue: U,
|
||||
): U;
|
||||
|
||||
/**
|
||||
* Reverses the elements in an Array.
|
||||
*/
|
||||
reverse(): this;
|
||||
|
||||
/**
|
||||
* Sets a value or an array of values.
|
||||
* @param array A typed or untyped array of values to set.
|
||||
* @param offset The index in the current array at which the values are to be written.
|
||||
*/
|
||||
set(array: ArrayLike<number>, offset?: number): void;
|
||||
|
||||
/**
|
||||
* Returns a section of an array.
|
||||
* @param start The beginning of the specified portion of the array.
|
||||
* @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
|
||||
*/
|
||||
slice(start?: number, end?: number): Float16Array;
|
||||
|
||||
/**
|
||||
* Determines whether the specified callback function returns true for any element of an array.
|
||||
* @param callbackfn A function that accepts up to three arguments. The some method calls
|
||||
* the callbackfn function for each element in the array until the callbackfn returns a value
|
||||
* which is coercible to the Boolean value true, or until the end of the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
|
||||
* If thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
some(
|
||||
callbackfn: (value: number, index: number, array: Float16Array) => unknown,
|
||||
thisArg?: any,
|
||||
): boolean;
|
||||
|
||||
/**
|
||||
* Sorts an array.
|
||||
* @param compareFn Function used to determine the order of the elements. It is expected to return
|
||||
* a negative value if first argument is less than second argument, zero if they're equal and a positive
|
||||
* value otherwise. If omitted, the elements are sorted in ascending.
|
||||
*/
|
||||
sort(compareFn?: (a: number, b: number) => number): this;
|
||||
|
||||
/**
|
||||
* Gets a new Float16Array view of the ArrayBuffer store for this array, referencing the elements
|
||||
* at begin, inclusive, up to end, exclusive.
|
||||
* @param begin The index of the beginning of the array.
|
||||
* @param end The index of the end of the array.
|
||||
*/
|
||||
subarray(begin?: number, end?: number): Float16Array;
|
||||
|
||||
/**
|
||||
* Copies the array and returns the copy with the elements in reverse order.
|
||||
*/
|
||||
toReversed(): Float16Array;
|
||||
|
||||
/**
|
||||
* Copies and sorts the array.
|
||||
* @param compareFn Function used to determine the order of the elements. It is expected to return
|
||||
* a negative value if first argument is less than second argument, zero if they're equal and a positive
|
||||
* value otherwise. If omitted, the elements are sorted in ascending.
|
||||
*/
|
||||
toSorted(compareFn?: (a: number, b: number) => number): Float16Array;
|
||||
|
||||
/**
|
||||
* Copies the array and replaces the element at the given index with the provided value.
|
||||
* @param index The zero-based location in the array for which to replace an element.
|
||||
* @param value Element to insert into the array in place of the replaced element.
|
||||
*/
|
||||
with(index: number, value: number): Float16Array;
|
||||
|
||||
/**
|
||||
* Converts a number to a string by using the current locale.
|
||||
*/
|
||||
toLocaleString(): string;
|
||||
|
||||
/**
|
||||
* Returns a string representation of an array.
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/**
|
||||
* Returns the primitive value of the specified object.
|
||||
*/
|
||||
valueOf(): Float16Array;
|
||||
|
||||
readonly [Symbol.toStringTag]: "Float16Array";
|
||||
|
||||
[index: number]: number;
|
||||
}
|
||||
|
||||
export interface Float16ArrayConstructor {
|
||||
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;
|
||||
|
||||
/**
|
||||
* The size in bytes of each element in the array.
|
||||
*/
|
||||
readonly BYTES_PER_ELEMENT: number;
|
||||
|
||||
/**
|
||||
* Returns a new array from a set of elements.
|
||||
* @param items A set of elements to include in the new array object.
|
||||
*/
|
||||
of(...items: number[]): Float16Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Float16Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(
|
||||
elements: Iterable<T>,
|
||||
mapfn: (v: T, k: number) => number,
|
||||
thisArg?: any,
|
||||
): Float16Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like object to convert to an array.
|
||||
*/
|
||||
from(arrayLike: ArrayLike<number>): Float16Array;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param arrayLike An array-like object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(
|
||||
arrayLike: ArrayLike<T>,
|
||||
mapfn: (v: T, k: number) => number,
|
||||
thisArg?: any,
|
||||
): Float16Array;
|
||||
}
|
||||
export declare const Float16Array: Float16ArrayConstructor;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value is a Float16Array instance.
|
||||
* @since v3.4.0
|
||||
*/
|
||||
export declare function isFloat16Array(value: unknown): value is Float16Array;
|
||||
|
||||
/**
|
||||
* Returns `true` if the value is a type of TypedArray instance that contains Float16Array.
|
||||
* @since v3.6.0
|
||||
*/
|
||||
export declare function isTypedArray(
|
||||
value: unknown,
|
||||
): value is
|
||||
| Uint8Array
|
||||
| Uint8ClampedArray
|
||||
| Uint16Array
|
||||
| Uint32Array
|
||||
| Int8Array
|
||||
| Int16Array
|
||||
| Int32Array
|
||||
| Float16Array
|
||||
| Float32Array
|
||||
| Float64Array
|
||||
| BigUint64Array
|
||||
| BigInt64Array;
|
||||
|
||||
/**
|
||||
* Gets the Float16 value at the specified byte offset from the start of the view. There is
|
||||
* no alignment constraint; multi-byte values may be fetched from any offset.
|
||||
* @param byteOffset The place in the buffer at which the value should be retrieved.
|
||||
* @param littleEndian If false or undefined, a big-endian value should be read,
|
||||
* otherwise a little-endian value should be read.
|
||||
*/
|
||||
export declare function getFloat16(
|
||||
dataView: DataView,
|
||||
byteOffset: number,
|
||||
littleEndian?: boolean,
|
||||
): number;
|
||||
|
||||
/**
|
||||
* Stores an Float16 value at the specified byte offset from the start of the view.
|
||||
* @param byteOffset The place in the buffer at which the value should be set.
|
||||
* @param value The value to set.
|
||||
* @param littleEndian If false or undefined, a big-endian value should be written,
|
||||
* otherwise a little-endian value should be written.
|
||||
*/
|
||||
export declare function setFloat16(
|
||||
dataView: DataView,
|
||||
byteOffset: number,
|
||||
value: number,
|
||||
littleEndian?: boolean,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Returns the nearest half-precision float representation of a number.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
export declare function f16round(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the nearest half-precision float representation of a number.
|
||||
* @alias f16round
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
export declare function hfround(x: number): number;
|
||||
25
node_modules/@petamoriken/float16/inspect/node.cjs
generated
vendored
Normal file
25
node_modules/@petamoriken/float16/inspect/node.cjs
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/* eslint-env node */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Custom inspect function for Node.js
|
||||
*
|
||||
* ```
|
||||
* Float16Array.prototype[Symbol.for("nodejs.util.inspect.custom")] = customInspect;
|
||||
* ```
|
||||
* @param {number} _deps
|
||||
* @param {import("node:util").InspectOptions} options
|
||||
* @param {import("node:util").inspect} inspect
|
||||
* @returns {string}
|
||||
*/
|
||||
exports.customInspect = function customInspect(_deps, options, inspect) {
|
||||
const length = this.length;
|
||||
|
||||
const array = [];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
array[i] = this[i];
|
||||
}
|
||||
|
||||
return `Float16Array(${length}) ${inspect(array, options)}`;
|
||||
};
|
||||
23
node_modules/@petamoriken/float16/inspect/node.mjs
generated
vendored
Normal file
23
node_modules/@petamoriken/float16/inspect/node.mjs
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/* eslint-env node */
|
||||
|
||||
/**
|
||||
* Custom inspect function for Node.js
|
||||
*
|
||||
* ```
|
||||
* Float16Array.prototype[Symbol.for("nodejs.util.inspect.custom")] = customInspect;
|
||||
* ```
|
||||
* @param {number} _deps
|
||||
* @param {import("node:util").InspectOptions} options
|
||||
* @param {import("node:util").inspect} inspect
|
||||
* @returns {string}
|
||||
*/
|
||||
export function customInspect(_deps, options, inspect) {
|
||||
const length = this.length;
|
||||
|
||||
const array = [];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
array[i] = this[i];
|
||||
}
|
||||
|
||||
return `Float16Array(${length}) ${inspect(array, options)}`;
|
||||
}
|
||||
16
node_modules/@petamoriken/float16/lib/DataView.cjs
generated
vendored
Normal file
16
node_modules/@petamoriken/float16/lib/DataView.cjs
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getFloat16 = getFloat16;
|
||||
exports.setFloat16 = setFloat16;
|
||||
var _arrayIterator = require("./_util/arrayIterator.cjs");
|
||||
var _converter = require("./_util/converter.cjs");
|
||||
var _primordials = require("./_util/primordials.cjs");
|
||||
function getFloat16(dataView, byteOffset, ...opts) {
|
||||
return (0, _converter.convertToNumber)((0, _primordials.DataViewPrototypeGetUint16)(dataView, byteOffset, ...(0, _arrayIterator.safeIfNeeded)(opts)));
|
||||
}
|
||||
function setFloat16(dataView, byteOffset, value, ...opts) {
|
||||
return (0, _primordials.DataViewPrototypeSetUint16)(dataView, byteOffset, (0, _converter.roundToFloat16Bits)(value), ...(0, _arrayIterator.safeIfNeeded)(opts));
|
||||
}
|
||||
690
node_modules/@petamoriken/float16/lib/Float16Array.cjs
generated
vendored
Normal file
690
node_modules/@petamoriken/float16/lib/Float16Array.cjs
generated
vendored
Normal file
@@ -0,0 +1,690 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isFloat16Array = isFloat16Array;
|
||||
var _arrayIterator = require("./_util/arrayIterator.cjs");
|
||||
var _brand = require("./_util/brand.cjs");
|
||||
var _converter = require("./_util/converter.cjs");
|
||||
var _is = require("./_util/is.cjs");
|
||||
var _messages = require("./_util/messages.cjs");
|
||||
var _primordials = require("./_util/primordials.cjs");
|
||||
var _spec = require("./_util/spec.cjs");
|
||||
const BYTES_PER_ELEMENT = 2;
|
||||
const float16bitsArrays = new _primordials.NativeWeakMap();
|
||||
function isFloat16Array(target) {
|
||||
return (0, _primordials.WeakMapPrototypeHas)(float16bitsArrays, target) || !(0, _primordials.ArrayBufferIsView)(target) && (0, _brand.hasFloat16ArrayBrand)(target);
|
||||
}
|
||||
function assertFloat16Array(target) {
|
||||
if (!isFloat16Array(target)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.THIS_IS_NOT_A_FLOAT16ARRAY_OBJECT);
|
||||
}
|
||||
}
|
||||
function assertSpeciesTypedArray(target, count) {
|
||||
const isTargetFloat16Array = isFloat16Array(target);
|
||||
const isTargetTypedArray = (0, _is.isNativeTypedArray)(target);
|
||||
if (!isTargetFloat16Array && !isTargetTypedArray) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.SPECIES_CONSTRUCTOR_DIDNT_RETURN_TYPEDARRAY_OBJECT);
|
||||
}
|
||||
if (typeof count === "number") {
|
||||
let length;
|
||||
if (isTargetFloat16Array) {
|
||||
const float16bitsArray = getFloat16BitsArray(target);
|
||||
length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
} else {
|
||||
length = (0, _primordials.TypedArrayPrototypeGetLength)(target);
|
||||
}
|
||||
if (length < count) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.DERIVED_CONSTRUCTOR_CREATED_TYPEDARRAY_OBJECT_WHICH_WAS_TOO_SMALL_LENGTH);
|
||||
}
|
||||
}
|
||||
if ((0, _is.isNativeBigIntTypedArray)(target)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.CANNOT_MIX_BIGINT_AND_OTHER_TYPES);
|
||||
}
|
||||
}
|
||||
function getFloat16BitsArray(float16) {
|
||||
const float16bitsArray = (0, _primordials.WeakMapPrototypeGet)(float16bitsArrays, float16);
|
||||
if (float16bitsArray !== undefined) {
|
||||
const buffer = (0, _primordials.TypedArrayPrototypeGetBuffer)(float16bitsArray);
|
||||
if ((0, _spec.IsDetachedBuffer)(buffer)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
|
||||
}
|
||||
return float16bitsArray;
|
||||
}
|
||||
const buffer = float16.buffer;
|
||||
if ((0, _spec.IsDetachedBuffer)(buffer)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
|
||||
}
|
||||
const cloned = (0, _primordials.ReflectConstruct)(Float16Array, [buffer, float16.byteOffset, float16.length], float16.constructor);
|
||||
return (0, _primordials.WeakMapPrototypeGet)(float16bitsArrays, cloned);
|
||||
}
|
||||
function copyToArray(float16bitsArray) {
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const array = [];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
array[i] = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
const TypedArrayPrototypeGetters = new _primordials.NativeWeakSet();
|
||||
for (const key of (0, _primordials.ReflectOwnKeys)(_primordials.TypedArrayPrototype)) {
|
||||
if (key === _primordials.SymbolToStringTag) {
|
||||
continue;
|
||||
}
|
||||
const descriptor = (0, _primordials.ReflectGetOwnPropertyDescriptor)(_primordials.TypedArrayPrototype, key);
|
||||
if ((0, _primordials.ObjectHasOwn)(descriptor, "get") && typeof descriptor.get === "function") {
|
||||
(0, _primordials.WeakSetPrototypeAdd)(TypedArrayPrototypeGetters, descriptor.get);
|
||||
}
|
||||
}
|
||||
const handler = (0, _primordials.ObjectFreeze)({
|
||||
get(target, key, receiver) {
|
||||
if ((0, _is.isCanonicalIntegerIndexString)(key) && (0, _primordials.ObjectHasOwn)(target, key)) {
|
||||
return (0, _converter.convertToNumber)((0, _primordials.ReflectGet)(target, key));
|
||||
}
|
||||
if ((0, _primordials.WeakSetPrototypeHas)(TypedArrayPrototypeGetters, (0, _primordials.ObjectPrototype__lookupGetter__)(target, key))) {
|
||||
return (0, _primordials.ReflectGet)(target, key);
|
||||
}
|
||||
return (0, _primordials.ReflectGet)(target, key, receiver);
|
||||
},
|
||||
set(target, key, value, receiver) {
|
||||
if ((0, _is.isCanonicalIntegerIndexString)(key) && (0, _primordials.ObjectHasOwn)(target, key)) {
|
||||
return (0, _primordials.ReflectSet)(target, key, (0, _converter.roundToFloat16Bits)(value));
|
||||
}
|
||||
return (0, _primordials.ReflectSet)(target, key, value, receiver);
|
||||
},
|
||||
getOwnPropertyDescriptor(target, key) {
|
||||
if ((0, _is.isCanonicalIntegerIndexString)(key) && (0, _primordials.ObjectHasOwn)(target, key)) {
|
||||
const descriptor = (0, _primordials.ReflectGetOwnPropertyDescriptor)(target, key);
|
||||
descriptor.value = (0, _converter.convertToNumber)(descriptor.value);
|
||||
return descriptor;
|
||||
}
|
||||
return (0, _primordials.ReflectGetOwnPropertyDescriptor)(target, key);
|
||||
},
|
||||
defineProperty(target, key, descriptor) {
|
||||
if ((0, _is.isCanonicalIntegerIndexString)(key) && (0, _primordials.ObjectHasOwn)(target, key) && (0, _primordials.ObjectHasOwn)(descriptor, "value")) {
|
||||
descriptor.value = (0, _converter.roundToFloat16Bits)(descriptor.value);
|
||||
return (0, _primordials.ReflectDefineProperty)(target, key, descriptor);
|
||||
}
|
||||
return (0, _primordials.ReflectDefineProperty)(target, key, descriptor);
|
||||
}
|
||||
});
|
||||
class Float16Array {
|
||||
constructor(input, _byteOffset, _length) {
|
||||
let float16bitsArray;
|
||||
if (isFloat16Array(input)) {
|
||||
float16bitsArray = (0, _primordials.ReflectConstruct)(_primordials.NativeUint16Array, [getFloat16BitsArray(input)], new.target);
|
||||
} else if ((0, _is.isObject)(input) && !(0, _is.isAnyArrayBuffer)(input)) {
|
||||
let list;
|
||||
let length;
|
||||
if ((0, _is.isNativeTypedArray)(input)) {
|
||||
list = input;
|
||||
length = (0, _primordials.TypedArrayPrototypeGetLength)(input);
|
||||
const buffer = (0, _primordials.TypedArrayPrototypeGetBuffer)(input);
|
||||
if ((0, _spec.IsDetachedBuffer)(buffer)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
|
||||
}
|
||||
if ((0, _is.isNativeBigIntTypedArray)(input)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.CANNOT_MIX_BIGINT_AND_OTHER_TYPES);
|
||||
}
|
||||
const data = new _primordials.NativeArrayBuffer(length * BYTES_PER_ELEMENT);
|
||||
float16bitsArray = (0, _primordials.ReflectConstruct)(_primordials.NativeUint16Array, [data], new.target);
|
||||
} else {
|
||||
const iterator = input[_primordials.SymbolIterator];
|
||||
if (iterator != null && typeof iterator !== "function") {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.ITERATOR_PROPERTY_IS_NOT_CALLABLE);
|
||||
}
|
||||
if (iterator != null) {
|
||||
if ((0, _is.isOrdinaryArray)(input)) {
|
||||
list = input;
|
||||
length = input.length;
|
||||
} else {
|
||||
list = [...(input)];
|
||||
length = list.length;
|
||||
}
|
||||
} else {
|
||||
list = input;
|
||||
length = (0, _spec.ToLength)(list.length);
|
||||
}
|
||||
float16bitsArray = (0, _primordials.ReflectConstruct)(_primordials.NativeUint16Array, [length], new.target);
|
||||
}
|
||||
for (let i = 0; i < length; ++i) {
|
||||
float16bitsArray[i] = (0, _converter.roundToFloat16Bits)(list[i]);
|
||||
}
|
||||
} else {
|
||||
float16bitsArray = (0, _primordials.ReflectConstruct)(_primordials.NativeUint16Array, arguments, new.target);
|
||||
}
|
||||
const proxy = new _primordials.NativeProxy(float16bitsArray, handler);
|
||||
(0, _primordials.WeakMapPrototypeSet)(float16bitsArrays, proxy, float16bitsArray);
|
||||
return proxy;
|
||||
}
|
||||
static from(src, ...opts) {
|
||||
const Constructor = this;
|
||||
if (!(0, _primordials.ReflectHas)(Constructor, _brand.brand)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.THIS_CONSTRUCTOR_IS_NOT_A_SUBCLASS_OF_FLOAT16ARRAY);
|
||||
}
|
||||
if (Constructor === Float16Array) {
|
||||
if (isFloat16Array(src) && opts.length === 0) {
|
||||
const float16bitsArray = getFloat16BitsArray(src);
|
||||
const uint16 = new _primordials.NativeUint16Array((0, _primordials.TypedArrayPrototypeGetBuffer)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetByteOffset)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray));
|
||||
return new Float16Array((0, _primordials.TypedArrayPrototypeGetBuffer)((0, _primordials.TypedArrayPrototypeSlice)(uint16)));
|
||||
}
|
||||
if (opts.length === 0) {
|
||||
return new Float16Array((0, _primordials.TypedArrayPrototypeGetBuffer)((0, _primordials.Uint16ArrayFrom)(src, _converter.roundToFloat16Bits)));
|
||||
}
|
||||
const mapFunc = opts[0];
|
||||
const thisArg = opts[1];
|
||||
return new Float16Array((0, _primordials.TypedArrayPrototypeGetBuffer)((0, _primordials.Uint16ArrayFrom)(src, function (val, ...args) {
|
||||
return (0, _converter.roundToFloat16Bits)((0, _primordials.ReflectApply)(mapFunc, this, [val, ...(0, _arrayIterator.safeIfNeeded)(args)]));
|
||||
}, thisArg)));
|
||||
}
|
||||
let list;
|
||||
let length;
|
||||
const iterator = src[_primordials.SymbolIterator];
|
||||
if (iterator != null && typeof iterator !== "function") {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.ITERATOR_PROPERTY_IS_NOT_CALLABLE);
|
||||
}
|
||||
if (iterator != null) {
|
||||
if ((0, _is.isOrdinaryArray)(src)) {
|
||||
list = src;
|
||||
length = src.length;
|
||||
} else if ((0, _is.isOrdinaryNativeTypedArray)(src)) {
|
||||
list = src;
|
||||
length = (0, _primordials.TypedArrayPrototypeGetLength)(src);
|
||||
} else {
|
||||
list = [...src];
|
||||
length = list.length;
|
||||
}
|
||||
} else {
|
||||
if (src == null) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT);
|
||||
}
|
||||
list = (0, _primordials.NativeObject)(src);
|
||||
length = (0, _spec.ToLength)(list.length);
|
||||
}
|
||||
const array = new Constructor(length);
|
||||
if (opts.length === 0) {
|
||||
for (let i = 0; i < length; ++i) {
|
||||
array[i] = list[i];
|
||||
}
|
||||
} else {
|
||||
const mapFunc = opts[0];
|
||||
const thisArg = opts[1];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
array[i] = (0, _primordials.ReflectApply)(mapFunc, thisArg, [list[i], i]);
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
static of(...items) {
|
||||
const Constructor = this;
|
||||
if (!(0, _primordials.ReflectHas)(Constructor, _brand.brand)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.THIS_CONSTRUCTOR_IS_NOT_A_SUBCLASS_OF_FLOAT16ARRAY);
|
||||
}
|
||||
const length = items.length;
|
||||
if (Constructor === Float16Array) {
|
||||
const proxy = new Float16Array(length);
|
||||
const float16bitsArray = getFloat16BitsArray(proxy);
|
||||
for (let i = 0; i < length; ++i) {
|
||||
float16bitsArray[i] = (0, _converter.roundToFloat16Bits)(items[i]);
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
const array = new Constructor(length);
|
||||
for (let i = 0; i < length; ++i) {
|
||||
array[i] = items[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
keys() {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
return (0, _primordials.TypedArrayPrototypeKeys)(float16bitsArray);
|
||||
}
|
||||
values() {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
return (0, _arrayIterator.wrap)(function* () {
|
||||
for (const val of (0, _primordials.TypedArrayPrototypeValues)(float16bitsArray)) {
|
||||
yield (0, _converter.convertToNumber)(val);
|
||||
}
|
||||
}());
|
||||
}
|
||||
entries() {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
return (0, _arrayIterator.wrap)(function* () {
|
||||
for (const [i, val] of (0, _primordials.TypedArrayPrototypeEntries)(float16bitsArray)) {
|
||||
yield ([i, (0, _converter.convertToNumber)(val)]);
|
||||
}
|
||||
}());
|
||||
}
|
||||
at(index) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const relativeIndex = (0, _spec.ToIntegerOrInfinity)(index);
|
||||
const k = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
|
||||
if (k < 0 || k >= length) {
|
||||
return;
|
||||
}
|
||||
return (0, _converter.convertToNumber)(float16bitsArray[k]);
|
||||
}
|
||||
with(index, value) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const relativeIndex = (0, _spec.ToIntegerOrInfinity)(index);
|
||||
const k = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
|
||||
const number = +value;
|
||||
if (k < 0 || k >= length) {
|
||||
throw (0, _primordials.NativeRangeError)(_messages.OFFSET_IS_OUT_OF_BOUNDS);
|
||||
}
|
||||
const uint16 = new _primordials.NativeUint16Array((0, _primordials.TypedArrayPrototypeGetBuffer)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetByteOffset)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray));
|
||||
const cloned = new Float16Array((0, _primordials.TypedArrayPrototypeGetBuffer)((0, _primordials.TypedArrayPrototypeSlice)(uint16)));
|
||||
const array = getFloat16BitsArray(cloned);
|
||||
array[k] = (0, _converter.roundToFloat16Bits)(number);
|
||||
return cloned;
|
||||
}
|
||||
map(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
const Constructor = (0, _spec.SpeciesConstructor)(float16bitsArray, Float16Array);
|
||||
if (Constructor === Float16Array) {
|
||||
const proxy = new Float16Array(length);
|
||||
const array = getFloat16BitsArray(proxy);
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const val = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
array[i] = (0, _converter.roundToFloat16Bits)((0, _primordials.ReflectApply)(callback, thisArg, [val, i, this]));
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
const array = new Constructor(length);
|
||||
assertSpeciesTypedArray(array, length);
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const val = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
array[i] = (0, _primordials.ReflectApply)(callback, thisArg, [val, i, this]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
filter(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
const kept = [];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const val = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
if ((0, _primordials.ReflectApply)(callback, thisArg, [val, i, this])) {
|
||||
(0, _primordials.ArrayPrototypePush)(kept, val);
|
||||
}
|
||||
}
|
||||
const Constructor = (0, _spec.SpeciesConstructor)(float16bitsArray, Float16Array);
|
||||
const array = new Constructor(kept);
|
||||
assertSpeciesTypedArray(array);
|
||||
return array;
|
||||
}
|
||||
reduce(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
if (length === 0 && opts.length === 0) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE);
|
||||
}
|
||||
let accumulator, start;
|
||||
if (opts.length === 0) {
|
||||
accumulator = (0, _converter.convertToNumber)(float16bitsArray[0]);
|
||||
start = 1;
|
||||
} else {
|
||||
accumulator = opts[0];
|
||||
start = 0;
|
||||
}
|
||||
for (let i = start; i < length; ++i) {
|
||||
accumulator = callback(accumulator, (0, _converter.convertToNumber)(float16bitsArray[i]), i, this);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
reduceRight(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
if (length === 0 && opts.length === 0) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE);
|
||||
}
|
||||
let accumulator, start;
|
||||
if (opts.length === 0) {
|
||||
accumulator = (0, _converter.convertToNumber)(float16bitsArray[length - 1]);
|
||||
start = length - 2;
|
||||
} else {
|
||||
accumulator = opts[0];
|
||||
start = length - 1;
|
||||
}
|
||||
for (let i = start; i >= 0; --i) {
|
||||
accumulator = callback(accumulator, (0, _converter.convertToNumber)(float16bitsArray[i]), i, this);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
forEach(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
(0, _primordials.ReflectApply)(callback, thisArg, [(0, _converter.convertToNumber)(float16bitsArray[i]), i, this]);
|
||||
}
|
||||
}
|
||||
find(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const value = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
if ((0, _primordials.ReflectApply)(callback, thisArg, [value, i, this])) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
findIndex(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
const value = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
if ((0, _primordials.ReflectApply)(callback, thisArg, [value, i, this])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
findLast(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
for (let i = length - 1; i >= 0; --i) {
|
||||
const value = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
if ((0, _primordials.ReflectApply)(callback, thisArg, [value, i, this])) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
findLastIndex(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
for (let i = length - 1; i >= 0; --i) {
|
||||
const value = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
if ((0, _primordials.ReflectApply)(callback, thisArg, [value, i, this])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
every(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
if (!(0, _primordials.ReflectApply)(callback, thisArg, [(0, _converter.convertToNumber)(float16bitsArray[i]), i, this])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
some(callback, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const thisArg = opts[0];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
if ((0, _primordials.ReflectApply)(callback, thisArg, [(0, _converter.convertToNumber)(float16bitsArray[i]), i, this])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
set(input, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const targetOffset = (0, _spec.ToIntegerOrInfinity)(opts[0]);
|
||||
if (targetOffset < 0) {
|
||||
throw (0, _primordials.NativeRangeError)(_messages.OFFSET_IS_OUT_OF_BOUNDS);
|
||||
}
|
||||
if (input == null) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT);
|
||||
}
|
||||
if ((0, _is.isNativeBigIntTypedArray)(input)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.CANNOT_MIX_BIGINT_AND_OTHER_TYPES);
|
||||
}
|
||||
if (isFloat16Array(input)) {
|
||||
return (0, _primordials.TypedArrayPrototypeSet)(getFloat16BitsArray(this), getFloat16BitsArray(input), targetOffset);
|
||||
}
|
||||
if ((0, _is.isNativeTypedArray)(input)) {
|
||||
const buffer = (0, _primordials.TypedArrayPrototypeGetBuffer)(input);
|
||||
if ((0, _spec.IsDetachedBuffer)(buffer)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
|
||||
}
|
||||
}
|
||||
const targetLength = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const src = (0, _primordials.NativeObject)(input);
|
||||
const srcLength = (0, _spec.ToLength)(src.length);
|
||||
if (targetOffset === Infinity || srcLength + targetOffset > targetLength) {
|
||||
throw (0, _primordials.NativeRangeError)(_messages.OFFSET_IS_OUT_OF_BOUNDS);
|
||||
}
|
||||
for (let i = 0; i < srcLength; ++i) {
|
||||
float16bitsArray[i + targetOffset] = (0, _converter.roundToFloat16Bits)(src[i]);
|
||||
}
|
||||
}
|
||||
reverse() {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
(0, _primordials.TypedArrayPrototypeReverse)(float16bitsArray);
|
||||
return this;
|
||||
}
|
||||
toReversed() {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const uint16 = new _primordials.NativeUint16Array((0, _primordials.TypedArrayPrototypeGetBuffer)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetByteOffset)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray));
|
||||
const cloned = new Float16Array((0, _primordials.TypedArrayPrototypeGetBuffer)((0, _primordials.TypedArrayPrototypeSlice)(uint16)));
|
||||
const clonedFloat16bitsArray = getFloat16BitsArray(cloned);
|
||||
(0, _primordials.TypedArrayPrototypeReverse)(clonedFloat16bitsArray);
|
||||
return cloned;
|
||||
}
|
||||
fill(value, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
(0, _primordials.TypedArrayPrototypeFill)(float16bitsArray, (0, _converter.roundToFloat16Bits)(value), ...(0, _arrayIterator.safeIfNeeded)(opts));
|
||||
return this;
|
||||
}
|
||||
copyWithin(target, start, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
(0, _primordials.TypedArrayPrototypeCopyWithin)(float16bitsArray, target, start, ...(0, _arrayIterator.safeIfNeeded)(opts));
|
||||
return this;
|
||||
}
|
||||
sort(compareFn) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const sortCompare = compareFn !== undefined ? compareFn : _spec.defaultCompare;
|
||||
(0, _primordials.TypedArrayPrototypeSort)(float16bitsArray, (x, y) => {
|
||||
return sortCompare((0, _converter.convertToNumber)(x), (0, _converter.convertToNumber)(y));
|
||||
});
|
||||
return this;
|
||||
}
|
||||
toSorted(compareFn) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
if (compareFn !== undefined && typeof compareFn !== "function") {
|
||||
throw new _primordials.NativeTypeError(_messages.THE_COMPARISON_FUNCTION_MUST_BE_EITHER_A_FUNCTION_OR_UNDEFINED);
|
||||
}
|
||||
const sortCompare = compareFn !== undefined ? compareFn : _spec.defaultCompare;
|
||||
const uint16 = new _primordials.NativeUint16Array((0, _primordials.TypedArrayPrototypeGetBuffer)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetByteOffset)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray));
|
||||
const cloned = new Float16Array((0, _primordials.TypedArrayPrototypeGetBuffer)((0, _primordials.TypedArrayPrototypeSlice)(uint16)));
|
||||
const clonedFloat16bitsArray = getFloat16BitsArray(cloned);
|
||||
(0, _primordials.TypedArrayPrototypeSort)(clonedFloat16bitsArray, (x, y) => {
|
||||
return sortCompare((0, _converter.convertToNumber)(x), (0, _converter.convertToNumber)(y));
|
||||
});
|
||||
return cloned;
|
||||
}
|
||||
slice(start, end) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const Constructor = (0, _spec.SpeciesConstructor)(float16bitsArray, Float16Array);
|
||||
if (Constructor === Float16Array) {
|
||||
const uint16 = new _primordials.NativeUint16Array((0, _primordials.TypedArrayPrototypeGetBuffer)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetByteOffset)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray));
|
||||
return new Float16Array((0, _primordials.TypedArrayPrototypeGetBuffer)((0, _primordials.TypedArrayPrototypeSlice)(uint16, start, end)));
|
||||
}
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
const relativeStart = (0, _spec.ToIntegerOrInfinity)(start);
|
||||
const relativeEnd = end === undefined ? length : (0, _spec.ToIntegerOrInfinity)(end);
|
||||
let k;
|
||||
if (relativeStart === -Infinity) {
|
||||
k = 0;
|
||||
} else if (relativeStart < 0) {
|
||||
k = length + relativeStart > 0 ? length + relativeStart : 0;
|
||||
} else {
|
||||
k = length < relativeStart ? length : relativeStart;
|
||||
}
|
||||
let final;
|
||||
if (relativeEnd === -Infinity) {
|
||||
final = 0;
|
||||
} else if (relativeEnd < 0) {
|
||||
final = length + relativeEnd > 0 ? length + relativeEnd : 0;
|
||||
} else {
|
||||
final = length < relativeEnd ? length : relativeEnd;
|
||||
}
|
||||
const count = final - k > 0 ? final - k : 0;
|
||||
const array = new Constructor(count);
|
||||
assertSpeciesTypedArray(array, count);
|
||||
if (count === 0) {
|
||||
return array;
|
||||
}
|
||||
const buffer = (0, _primordials.TypedArrayPrototypeGetBuffer)(float16bitsArray);
|
||||
if ((0, _spec.IsDetachedBuffer)(buffer)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
|
||||
}
|
||||
let n = 0;
|
||||
while (k < final) {
|
||||
array[n] = (0, _converter.convertToNumber)(float16bitsArray[k]);
|
||||
++k;
|
||||
++n;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
subarray(begin, end) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const Constructor = (0, _spec.SpeciesConstructor)(float16bitsArray, Float16Array);
|
||||
const uint16 = new _primordials.NativeUint16Array((0, _primordials.TypedArrayPrototypeGetBuffer)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetByteOffset)(float16bitsArray), (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray));
|
||||
const uint16Subarray = (0, _primordials.TypedArrayPrototypeSubarray)(uint16, begin, end);
|
||||
const array = new Constructor((0, _primordials.TypedArrayPrototypeGetBuffer)(uint16Subarray), (0, _primordials.TypedArrayPrototypeGetByteOffset)(uint16Subarray), (0, _primordials.TypedArrayPrototypeGetLength)(uint16Subarray));
|
||||
assertSpeciesTypedArray(array);
|
||||
return array;
|
||||
}
|
||||
indexOf(element, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
let from = (0, _spec.ToIntegerOrInfinity)(opts[0]);
|
||||
if (from === Infinity) {
|
||||
return -1;
|
||||
}
|
||||
if (from < 0) {
|
||||
from += length;
|
||||
if (from < 0) {
|
||||
from = 0;
|
||||
}
|
||||
}
|
||||
for (let i = from; i < length; ++i) {
|
||||
if ((0, _primordials.ObjectHasOwn)(float16bitsArray, i) && (0, _converter.convertToNumber)(float16bitsArray[i]) === element) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
lastIndexOf(element, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
let from = opts.length >= 1 ? (0, _spec.ToIntegerOrInfinity)(opts[0]) : length - 1;
|
||||
if (from === -Infinity) {
|
||||
return -1;
|
||||
}
|
||||
if (from >= 0) {
|
||||
from = from < length - 1 ? from : length - 1;
|
||||
} else {
|
||||
from += length;
|
||||
}
|
||||
for (let i = from; i >= 0; --i) {
|
||||
if ((0, _primordials.ObjectHasOwn)(float16bitsArray, i) && (0, _converter.convertToNumber)(float16bitsArray[i]) === element) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
includes(element, ...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const length = (0, _primordials.TypedArrayPrototypeGetLength)(float16bitsArray);
|
||||
let from = (0, _spec.ToIntegerOrInfinity)(opts[0]);
|
||||
if (from === Infinity) {
|
||||
return false;
|
||||
}
|
||||
if (from < 0) {
|
||||
from += length;
|
||||
if (from < 0) {
|
||||
from = 0;
|
||||
}
|
||||
}
|
||||
const isNaN = (0, _primordials.NumberIsNaN)(element);
|
||||
for (let i = from; i < length; ++i) {
|
||||
const value = (0, _converter.convertToNumber)(float16bitsArray[i]);
|
||||
if (isNaN && (0, _primordials.NumberIsNaN)(value)) {
|
||||
return true;
|
||||
}
|
||||
if (value === element) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
join(separator) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const array = copyToArray(float16bitsArray);
|
||||
return (0, _primordials.ArrayPrototypeJoin)(array, separator);
|
||||
}
|
||||
toLocaleString(...opts) {
|
||||
assertFloat16Array(this);
|
||||
const float16bitsArray = getFloat16BitsArray(this);
|
||||
const array = copyToArray(float16bitsArray);
|
||||
return (0, _primordials.ArrayPrototypeToLocaleString)(array, ...(0, _arrayIterator.safeIfNeeded)(opts));
|
||||
}
|
||||
get [_primordials.SymbolToStringTag]() {
|
||||
if (isFloat16Array(this)) {
|
||||
return "Float16Array";
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Float16Array = Float16Array;
|
||||
(0, _primordials.ObjectDefineProperty)(Float16Array, "BYTES_PER_ELEMENT", {
|
||||
value: BYTES_PER_ELEMENT
|
||||
});
|
||||
(0, _primordials.ObjectDefineProperty)(Float16Array, _brand.brand, {});
|
||||
(0, _primordials.ReflectSetPrototypeOf)(Float16Array, _primordials.TypedArray);
|
||||
const Float16ArrayPrototype = Float16Array.prototype;
|
||||
(0, _primordials.ObjectDefineProperty)(Float16ArrayPrototype, "BYTES_PER_ELEMENT", {
|
||||
value: BYTES_PER_ELEMENT
|
||||
});
|
||||
(0, _primordials.ObjectDefineProperty)(Float16ArrayPrototype, _primordials.SymbolIterator, {
|
||||
value: Float16ArrayPrototype.values,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
||||
(0, _primordials.ReflectSetPrototypeOf)(Float16ArrayPrototype, _primordials.TypedArrayPrototype);
|
||||
52
node_modules/@petamoriken/float16/lib/_util/arrayIterator.cjs
generated
vendored
Normal file
52
node_modules/@petamoriken/float16/lib/_util/arrayIterator.cjs
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.safeIfNeeded = safeIfNeeded;
|
||||
exports.wrap = wrap;
|
||||
var _primordials = require("./primordials.cjs");
|
||||
const arrayIterators = new _primordials.NativeWeakMap();
|
||||
const SafeIteratorPrototype = (0, _primordials.ObjectCreate)(null, {
|
||||
next: {
|
||||
value: function next() {
|
||||
const arrayIterator = (0, _primordials.WeakMapPrototypeGet)(arrayIterators, this);
|
||||
return (0, _primordials.ArrayIteratorPrototypeNext)(arrayIterator);
|
||||
}
|
||||
},
|
||||
[_primordials.SymbolIterator]: {
|
||||
value: function values() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
});
|
||||
function safeIfNeeded(array) {
|
||||
if (array[_primordials.SymbolIterator] === _primordials.NativeArrayPrototypeSymbolIterator && _primordials.ArrayIteratorPrototype.next === _primordials.ArrayIteratorPrototypeNext) {
|
||||
return array;
|
||||
}
|
||||
const safe = (0, _primordials.ObjectCreate)(SafeIteratorPrototype);
|
||||
(0, _primordials.WeakMapPrototypeSet)(arrayIterators, safe, (0, _primordials.ArrayPrototypeSymbolIterator)(array));
|
||||
return safe;
|
||||
}
|
||||
const generators = new _primordials.NativeWeakMap();
|
||||
const DummyArrayIteratorPrototype = (0, _primordials.ObjectCreate)(_primordials.IteratorPrototype, {
|
||||
next: {
|
||||
value: function next() {
|
||||
const generator = (0, _primordials.WeakMapPrototypeGet)(generators, this);
|
||||
return (0, _primordials.GeneratorPrototypeNext)(generator);
|
||||
},
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
for (const key of (0, _primordials.ReflectOwnKeys)(_primordials.ArrayIteratorPrototype)) {
|
||||
if (key === "next") {
|
||||
continue;
|
||||
}
|
||||
(0, _primordials.ObjectDefineProperty)(DummyArrayIteratorPrototype, key, (0, _primordials.ReflectGetOwnPropertyDescriptor)(_primordials.ArrayIteratorPrototype, key));
|
||||
}
|
||||
function wrap(generator) {
|
||||
const dummy = (0, _primordials.ObjectCreate)(DummyArrayIteratorPrototype);
|
||||
(0, _primordials.WeakMapPrototypeSet)(generators, dummy, generator);
|
||||
return dummy;
|
||||
}
|
||||
27
node_modules/@petamoriken/float16/lib/_util/brand.cjs
generated
vendored
Normal file
27
node_modules/@petamoriken/float16/lib/_util/brand.cjs
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.hasFloat16ArrayBrand = hasFloat16ArrayBrand;
|
||||
var _is = require("./is.cjs");
|
||||
var _messages = require("./messages.cjs");
|
||||
var _primordials = require("./primordials.cjs");
|
||||
const brand = exports.brand = (0, _primordials.SymbolFor)("__Float16Array__");
|
||||
function hasFloat16ArrayBrand(target) {
|
||||
if (!(0, _is.isObjectLike)(target)) {
|
||||
return false;
|
||||
}
|
||||
const prototype = (0, _primordials.ReflectGetPrototypeOf)(target);
|
||||
if (!(0, _is.isObjectLike)(prototype)) {
|
||||
return false;
|
||||
}
|
||||
const constructor = prototype.constructor;
|
||||
if (constructor === undefined) {
|
||||
return false;
|
||||
}
|
||||
if (!(0, _is.isObject)(constructor)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT);
|
||||
}
|
||||
return (0, _primordials.ReflectHas)(constructor, brand);
|
||||
}
|
||||
111
node_modules/@petamoriken/float16/lib/_util/converter.cjs
generated
vendored
Normal file
111
node_modules/@petamoriken/float16/lib/_util/converter.cjs
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.convertToNumber = convertToNumber;
|
||||
exports.roundToFloat16 = roundToFloat16;
|
||||
exports.roundToFloat16Bits = roundToFloat16Bits;
|
||||
var _primordials = require("./primordials.cjs");
|
||||
const INVERSE_OF_EPSILON = 1 / _primordials.EPSILON;
|
||||
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;
|
||||
function roundToFloat16(num) {
|
||||
const number = +num;
|
||||
if (!(0, _primordials.NumberIsFinite)(number) || number === 0) {
|
||||
return number;
|
||||
}
|
||||
const sign = number > 0 ? 1 : -1;
|
||||
const absolute = (0, _primordials.MathAbs)(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);
|
||||
if (result > FLOAT16_MAX_VALUE || (0, _primordials.NumberIsNaN)(result)) {
|
||||
return sign * Infinity;
|
||||
}
|
||||
return sign * result;
|
||||
}
|
||||
const buffer = new _primordials.NativeArrayBuffer(4);
|
||||
const floatView = new _primordials.NativeFloat32Array(buffer);
|
||||
const uint32View = new _primordials.NativeUint32Array(buffer);
|
||||
const baseTable = new _primordials.NativeUint16Array(512);
|
||||
const shiftTable = new _primordials.NativeUint8Array(512);
|
||||
for (let i = 0; i < 256; ++i) {
|
||||
const e = i - 127;
|
||||
if (e < -24) {
|
||||
baseTable[i] = 0x0000;
|
||||
baseTable[i | 0x100] = 0x8000;
|
||||
shiftTable[i] = 24;
|
||||
shiftTable[i | 0x100] = 24;
|
||||
} 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;
|
||||
} else if (e <= 15) {
|
||||
baseTable[i] = e + 15 << 10;
|
||||
baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
|
||||
shiftTable[i] = 13;
|
||||
shiftTable[i | 0x100] = 13;
|
||||
} else if (e < 128) {
|
||||
baseTable[i] = 0x7c00;
|
||||
baseTable[i | 0x100] = 0xfc00;
|
||||
shiftTable[i] = 24;
|
||||
shiftTable[i | 0x100] = 24;
|
||||
} else {
|
||||
baseTable[i] = 0x7c00;
|
||||
baseTable[i | 0x100] = 0xfc00;
|
||||
shiftTable[i] = 13;
|
||||
shiftTable[i | 0x100] = 13;
|
||||
}
|
||||
}
|
||||
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 _primordials.NativeUint32Array(2048);
|
||||
for (let i = 1; i < 1024; ++i) {
|
||||
let m = i << 13;
|
||||
let e = 0;
|
||||
while ((m & 0x00800000) === 0) {
|
||||
m <<= 1;
|
||||
e -= 0x00800000;
|
||||
}
|
||||
m &= ~0x00800000;
|
||||
e += 0x38800000;
|
||||
mantissaTable[i] = m | e;
|
||||
}
|
||||
for (let i = 1024; i < 2048; ++i) {
|
||||
mantissaTable[i] = 0x38000000 + (i - 1024 << 13);
|
||||
}
|
||||
const exponentTable = new _primordials.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 _primordials.NativeUint16Array(64);
|
||||
for (let i = 1; i < 64; ++i) {
|
||||
if (i !== 32) {
|
||||
offsetTable[i] = 1024;
|
||||
}
|
||||
}
|
||||
function convertToNumber(float16bits) {
|
||||
const i = float16bits >> 10;
|
||||
uint32View[0] = mantissaTable[offsetTable[i] + (float16bits & 0x3ff)] + exponentTable[i];
|
||||
return floatView[0];
|
||||
}
|
||||
78
node_modules/@petamoriken/float16/lib/_util/is.cjs
generated
vendored
Normal file
78
node_modules/@petamoriken/float16/lib/_util/is.cjs
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isAnyArrayBuffer = isAnyArrayBuffer;
|
||||
exports.isCanonicalIntegerIndexString = isCanonicalIntegerIndexString;
|
||||
exports.isNativeBigIntTypedArray = isNativeBigIntTypedArray;
|
||||
exports.isNativeTypedArray = isNativeTypedArray;
|
||||
exports.isObject = isObject;
|
||||
exports.isObjectLike = isObjectLike;
|
||||
exports.isOrdinaryArray = isOrdinaryArray;
|
||||
exports.isOrdinaryNativeTypedArray = isOrdinaryNativeTypedArray;
|
||||
exports.isSharedArrayBuffer = isSharedArrayBuffer;
|
||||
var _primordials = require("./primordials.cjs");
|
||||
function isObject(value) {
|
||||
return value !== null && typeof value === "object" || typeof value === "function";
|
||||
}
|
||||
function isObjectLike(value) {
|
||||
return value !== null && typeof value === "object";
|
||||
}
|
||||
function isNativeTypedArray(value) {
|
||||
return (0, _primordials.TypedArrayPrototypeGetSymbolToStringTag)(value) !== undefined;
|
||||
}
|
||||
function isNativeBigIntTypedArray(value) {
|
||||
const typedArrayName = (0, _primordials.TypedArrayPrototypeGetSymbolToStringTag)(value);
|
||||
return typedArrayName === "BigInt64Array" || typedArrayName === "BigUint64Array";
|
||||
}
|
||||
function isArrayBuffer(value) {
|
||||
try {
|
||||
if ((0, _primordials.ArrayIsArray)(value)) {
|
||||
return false;
|
||||
}
|
||||
(0, _primordials.ArrayBufferPrototypeGetByteLength)(value);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isSharedArrayBuffer(value) {
|
||||
if (_primordials.NativeSharedArrayBuffer === null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
(0, _primordials.SharedArrayBufferPrototypeGetByteLength)(value);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isAnyArrayBuffer(value) {
|
||||
return isArrayBuffer(value) || isSharedArrayBuffer(value);
|
||||
}
|
||||
function isOrdinaryArray(value) {
|
||||
if (!(0, _primordials.ArrayIsArray)(value)) {
|
||||
return false;
|
||||
}
|
||||
return value[_primordials.SymbolIterator] === _primordials.NativeArrayPrototypeSymbolIterator && _primordials.ArrayIteratorPrototype.next === _primordials.ArrayIteratorPrototypeNext;
|
||||
}
|
||||
function isOrdinaryNativeTypedArray(value) {
|
||||
if (!isNativeTypedArray(value)) {
|
||||
return false;
|
||||
}
|
||||
return value[_primordials.SymbolIterator] === _primordials.NativeTypedArrayPrototypeSymbolIterator && _primordials.ArrayIteratorPrototype.next === _primordials.ArrayIteratorPrototypeNext;
|
||||
}
|
||||
function isCanonicalIntegerIndexString(value) {
|
||||
if (typeof value !== "string") {
|
||||
return false;
|
||||
}
|
||||
const number = +value;
|
||||
if (value !== number + "") {
|
||||
return false;
|
||||
}
|
||||
if (!(0, _primordials.NumberIsFinite)(number)) {
|
||||
return false;
|
||||
}
|
||||
return number === (0, _primordials.MathTrunc)(number);
|
||||
}
|
||||
18
node_modules/@petamoriken/float16/lib/_util/messages.cjs
generated
vendored
Normal file
18
node_modules/@petamoriken/float16/lib/_util/messages.cjs
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
const THIS_IS_NOT_AN_OBJECT = exports.THIS_IS_NOT_AN_OBJECT = "This is not an object";
|
||||
const THIS_IS_NOT_A_FLOAT16ARRAY_OBJECT = exports.THIS_IS_NOT_A_FLOAT16ARRAY_OBJECT = "This is not a Float16Array object";
|
||||
const THIS_CONSTRUCTOR_IS_NOT_A_SUBCLASS_OF_FLOAT16ARRAY = exports.THIS_CONSTRUCTOR_IS_NOT_A_SUBCLASS_OF_FLOAT16ARRAY = "This constructor is not a subclass of Float16Array";
|
||||
const THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT = exports.THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT = "The constructor property value is not an object";
|
||||
const SPECIES_CONSTRUCTOR_DIDNT_RETURN_TYPEDARRAY_OBJECT = exports.SPECIES_CONSTRUCTOR_DIDNT_RETURN_TYPEDARRAY_OBJECT = "Species constructor didn't return TypedArray object";
|
||||
const DERIVED_CONSTRUCTOR_CREATED_TYPEDARRAY_OBJECT_WHICH_WAS_TOO_SMALL_LENGTH = exports.DERIVED_CONSTRUCTOR_CREATED_TYPEDARRAY_OBJECT_WHICH_WAS_TOO_SMALL_LENGTH = "Derived constructor created TypedArray object which was too small length";
|
||||
const ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER = exports.ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER = "Attempting to access detached ArrayBuffer";
|
||||
const CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT = exports.CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT = "Cannot convert undefined or null to object";
|
||||
const CANNOT_MIX_BIGINT_AND_OTHER_TYPES = exports.CANNOT_MIX_BIGINT_AND_OTHER_TYPES = "Cannot mix BigInt and other types, use explicit conversions";
|
||||
const ITERATOR_PROPERTY_IS_NOT_CALLABLE = exports.ITERATOR_PROPERTY_IS_NOT_CALLABLE = "@@iterator property is not callable";
|
||||
const REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE = exports.REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE = "Reduce of empty array with no initial value";
|
||||
const THE_COMPARISON_FUNCTION_MUST_BE_EITHER_A_FUNCTION_OR_UNDEFINED = exports.THE_COMPARISON_FUNCTION_MUST_BE_EITHER_A_FUNCTION_OR_UNDEFINED = "The comparison function must be either a function or undefined";
|
||||
const OFFSET_IS_OUT_OF_BOUNDS = exports.OFFSET_IS_OUT_OF_BOUNDS = "Offset is out of bounds";
|
||||
150
node_modules/@petamoriken/float16/lib/_util/primordials.cjs
generated
vendored
Normal file
150
node_modules/@petamoriken/float16/lib/_util/primordials.cjs
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var _messages = require("./messages.cjs");
|
||||
function uncurryThis(target) {
|
||||
return (thisArg, ...args) => {
|
||||
return ReflectApply(target, thisArg, args);
|
||||
};
|
||||
}
|
||||
function uncurryThisGetter(target, key) {
|
||||
return uncurryThis(ReflectGetOwnPropertyDescriptor(target, key).get);
|
||||
}
|
||||
const {
|
||||
apply: ReflectApply,
|
||||
construct: ReflectConstruct,
|
||||
defineProperty: ReflectDefineProperty,
|
||||
get: ReflectGet,
|
||||
getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
|
||||
getPrototypeOf: ReflectGetPrototypeOf,
|
||||
has: ReflectHas,
|
||||
ownKeys: ReflectOwnKeys,
|
||||
set: ReflectSet,
|
||||
setPrototypeOf: ReflectSetPrototypeOf
|
||||
} = Reflect;
|
||||
exports.ReflectSetPrototypeOf = ReflectSetPrototypeOf;
|
||||
exports.ReflectSet = ReflectSet;
|
||||
exports.ReflectOwnKeys = ReflectOwnKeys;
|
||||
exports.ReflectHas = ReflectHas;
|
||||
exports.ReflectGetPrototypeOf = ReflectGetPrototypeOf;
|
||||
exports.ReflectGetOwnPropertyDescriptor = ReflectGetOwnPropertyDescriptor;
|
||||
exports.ReflectGet = ReflectGet;
|
||||
exports.ReflectDefineProperty = ReflectDefineProperty;
|
||||
exports.ReflectConstruct = ReflectConstruct;
|
||||
exports.ReflectApply = ReflectApply;
|
||||
const NativeProxy = exports.NativeProxy = Proxy;
|
||||
const {
|
||||
EPSILON,
|
||||
MAX_SAFE_INTEGER,
|
||||
isFinite: NumberIsFinite,
|
||||
isNaN: NumberIsNaN
|
||||
} = Number;
|
||||
exports.NumberIsNaN = NumberIsNaN;
|
||||
exports.NumberIsFinite = NumberIsFinite;
|
||||
exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
|
||||
exports.EPSILON = EPSILON;
|
||||
const {
|
||||
iterator: SymbolIterator,
|
||||
species: SymbolSpecies,
|
||||
toStringTag: SymbolToStringTag,
|
||||
for: SymbolFor
|
||||
} = Symbol;
|
||||
exports.SymbolFor = SymbolFor;
|
||||
exports.SymbolToStringTag = SymbolToStringTag;
|
||||
exports.SymbolSpecies = SymbolSpecies;
|
||||
exports.SymbolIterator = SymbolIterator;
|
||||
const NativeObject = exports.NativeObject = Object;
|
||||
const {
|
||||
create: ObjectCreate,
|
||||
defineProperty: ObjectDefineProperty,
|
||||
freeze: ObjectFreeze,
|
||||
is: ObjectIs
|
||||
} = NativeObject;
|
||||
exports.ObjectIs = ObjectIs;
|
||||
exports.ObjectFreeze = ObjectFreeze;
|
||||
exports.ObjectDefineProperty = ObjectDefineProperty;
|
||||
exports.ObjectCreate = ObjectCreate;
|
||||
const ObjectPrototype = NativeObject.prototype;
|
||||
const ObjectPrototype__lookupGetter__ = exports.ObjectPrototype__lookupGetter__ = ObjectPrototype.__lookupGetter__ ? uncurryThis(ObjectPrototype.__lookupGetter__) : (object, key) => {
|
||||
if (object == null) {
|
||||
throw NativeTypeError(_messages.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);
|
||||
};
|
||||
const ObjectHasOwn = exports.ObjectHasOwn = NativeObject.hasOwn || uncurryThis(ObjectPrototype.hasOwnProperty);
|
||||
const NativeArray = Array;
|
||||
const ArrayIsArray = exports.ArrayIsArray = NativeArray.isArray;
|
||||
const ArrayPrototype = NativeArray.prototype;
|
||||
const ArrayPrototypeJoin = exports.ArrayPrototypeJoin = uncurryThis(ArrayPrototype.join);
|
||||
const ArrayPrototypePush = exports.ArrayPrototypePush = uncurryThis(ArrayPrototype.push);
|
||||
const ArrayPrototypeToLocaleString = exports.ArrayPrototypeToLocaleString = uncurryThis(ArrayPrototype.toLocaleString);
|
||||
const NativeArrayPrototypeSymbolIterator = exports.NativeArrayPrototypeSymbolIterator = ArrayPrototype[SymbolIterator];
|
||||
const ArrayPrototypeSymbolIterator = exports.ArrayPrototypeSymbolIterator = uncurryThis(NativeArrayPrototypeSymbolIterator);
|
||||
const {
|
||||
abs: MathAbs,
|
||||
trunc: MathTrunc
|
||||
} = Math;
|
||||
exports.MathTrunc = MathTrunc;
|
||||
exports.MathAbs = MathAbs;
|
||||
const NativeArrayBuffer = exports.NativeArrayBuffer = ArrayBuffer;
|
||||
const ArrayBufferIsView = exports.ArrayBufferIsView = NativeArrayBuffer.isView;
|
||||
const ArrayBufferPrototype = NativeArrayBuffer.prototype;
|
||||
const ArrayBufferPrototypeSlice = exports.ArrayBufferPrototypeSlice = uncurryThis(ArrayBufferPrototype.slice);
|
||||
const ArrayBufferPrototypeGetByteLength = exports.ArrayBufferPrototypeGetByteLength = uncurryThisGetter(ArrayBufferPrototype, "byteLength");
|
||||
const NativeSharedArrayBuffer = exports.NativeSharedArrayBuffer = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : null;
|
||||
const SharedArrayBufferPrototypeGetByteLength = exports.SharedArrayBufferPrototypeGetByteLength = NativeSharedArrayBuffer && uncurryThisGetter(NativeSharedArrayBuffer.prototype, "byteLength");
|
||||
const TypedArray = exports.TypedArray = ReflectGetPrototypeOf(Uint8Array);
|
||||
const TypedArrayFrom = TypedArray.from;
|
||||
const TypedArrayPrototype = exports.TypedArrayPrototype = TypedArray.prototype;
|
||||
const NativeTypedArrayPrototypeSymbolIterator = exports.NativeTypedArrayPrototypeSymbolIterator = TypedArrayPrototype[SymbolIterator];
|
||||
const TypedArrayPrototypeKeys = exports.TypedArrayPrototypeKeys = uncurryThis(TypedArrayPrototype.keys);
|
||||
const TypedArrayPrototypeValues = exports.TypedArrayPrototypeValues = uncurryThis(TypedArrayPrototype.values);
|
||||
const TypedArrayPrototypeEntries = exports.TypedArrayPrototypeEntries = uncurryThis(TypedArrayPrototype.entries);
|
||||
const TypedArrayPrototypeSet = exports.TypedArrayPrototypeSet = uncurryThis(TypedArrayPrototype.set);
|
||||
const TypedArrayPrototypeReverse = exports.TypedArrayPrototypeReverse = uncurryThis(TypedArrayPrototype.reverse);
|
||||
const TypedArrayPrototypeFill = exports.TypedArrayPrototypeFill = uncurryThis(TypedArrayPrototype.fill);
|
||||
const TypedArrayPrototypeCopyWithin = exports.TypedArrayPrototypeCopyWithin = uncurryThis(TypedArrayPrototype.copyWithin);
|
||||
const TypedArrayPrototypeSort = exports.TypedArrayPrototypeSort = uncurryThis(TypedArrayPrototype.sort);
|
||||
const TypedArrayPrototypeSlice = exports.TypedArrayPrototypeSlice = uncurryThis(TypedArrayPrototype.slice);
|
||||
const TypedArrayPrototypeSubarray = exports.TypedArrayPrototypeSubarray = uncurryThis(TypedArrayPrototype.subarray);
|
||||
const TypedArrayPrototypeGetBuffer = exports.TypedArrayPrototypeGetBuffer = uncurryThisGetter(TypedArrayPrototype, "buffer");
|
||||
const TypedArrayPrototypeGetByteOffset = exports.TypedArrayPrototypeGetByteOffset = uncurryThisGetter(TypedArrayPrototype, "byteOffset");
|
||||
const TypedArrayPrototypeGetLength = exports.TypedArrayPrototypeGetLength = uncurryThisGetter(TypedArrayPrototype, "length");
|
||||
const TypedArrayPrototypeGetSymbolToStringTag = exports.TypedArrayPrototypeGetSymbolToStringTag = uncurryThisGetter(TypedArrayPrototype, SymbolToStringTag);
|
||||
const NativeUint8Array = exports.NativeUint8Array = Uint8Array;
|
||||
const NativeUint16Array = exports.NativeUint16Array = Uint16Array;
|
||||
const Uint16ArrayFrom = (...args) => {
|
||||
return ReflectApply(TypedArrayFrom, NativeUint16Array, args);
|
||||
};
|
||||
exports.Uint16ArrayFrom = Uint16ArrayFrom;
|
||||
const NativeUint32Array = exports.NativeUint32Array = Uint32Array;
|
||||
const NativeFloat32Array = exports.NativeFloat32Array = Float32Array;
|
||||
const ArrayIteratorPrototype = exports.ArrayIteratorPrototype = ReflectGetPrototypeOf([][SymbolIterator]());
|
||||
const ArrayIteratorPrototypeNext = exports.ArrayIteratorPrototypeNext = uncurryThis(ArrayIteratorPrototype.next);
|
||||
const GeneratorPrototypeNext = exports.GeneratorPrototypeNext = uncurryThis(function* () {}().next);
|
||||
const IteratorPrototype = exports.IteratorPrototype = ReflectGetPrototypeOf(ArrayIteratorPrototype);
|
||||
const DataViewPrototype = DataView.prototype;
|
||||
const DataViewPrototypeGetUint16 = exports.DataViewPrototypeGetUint16 = uncurryThis(DataViewPrototype.getUint16);
|
||||
const DataViewPrototypeSetUint16 = exports.DataViewPrototypeSetUint16 = uncurryThis(DataViewPrototype.setUint16);
|
||||
const NativeTypeError = exports.NativeTypeError = TypeError;
|
||||
const NativeRangeError = exports.NativeRangeError = RangeError;
|
||||
const NativeWeakSet = exports.NativeWeakSet = WeakSet;
|
||||
const WeakSetPrototype = NativeWeakSet.prototype;
|
||||
const WeakSetPrototypeAdd = exports.WeakSetPrototypeAdd = uncurryThis(WeakSetPrototype.add);
|
||||
const WeakSetPrototypeHas = exports.WeakSetPrototypeHas = uncurryThis(WeakSetPrototype.has);
|
||||
const NativeWeakMap = exports.NativeWeakMap = WeakMap;
|
||||
const WeakMapPrototype = NativeWeakMap.prototype;
|
||||
const WeakMapPrototypeGet = exports.WeakMapPrototypeGet = uncurryThis(WeakMapPrototype.get);
|
||||
const WeakMapPrototypeHas = exports.WeakMapPrototypeHas = uncurryThis(WeakMapPrototype.has);
|
||||
const WeakMapPrototypeSet = exports.WeakMapPrototypeSet = uncurryThis(WeakMapPrototype.set);
|
||||
84
node_modules/@petamoriken/float16/lib/_util/spec.cjs
generated
vendored
Normal file
84
node_modules/@petamoriken/float16/lib/_util/spec.cjs
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.IsDetachedBuffer = IsDetachedBuffer;
|
||||
exports.SpeciesConstructor = SpeciesConstructor;
|
||||
exports.ToIntegerOrInfinity = ToIntegerOrInfinity;
|
||||
exports.ToLength = ToLength;
|
||||
exports.defaultCompare = defaultCompare;
|
||||
var _is = require("./is.cjs");
|
||||
var _messages = require("./messages.cjs");
|
||||
var _primordials = require("./primordials.cjs");
|
||||
function ToIntegerOrInfinity(target) {
|
||||
const number = +target;
|
||||
if ((0, _primordials.NumberIsNaN)(number) || number === 0) {
|
||||
return 0;
|
||||
}
|
||||
return (0, _primordials.MathTrunc)(number);
|
||||
}
|
||||
function ToLength(target) {
|
||||
const length = ToIntegerOrInfinity(target);
|
||||
if (length < 0) {
|
||||
return 0;
|
||||
}
|
||||
return length < _primordials.MAX_SAFE_INTEGER ? length : _primordials.MAX_SAFE_INTEGER;
|
||||
}
|
||||
function SpeciesConstructor(target, defaultConstructor) {
|
||||
if (!(0, _is.isObject)(target)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.THIS_IS_NOT_AN_OBJECT);
|
||||
}
|
||||
const constructor = target.constructor;
|
||||
if (constructor === undefined) {
|
||||
return defaultConstructor;
|
||||
}
|
||||
if (!(0, _is.isObject)(constructor)) {
|
||||
throw (0, _primordials.NativeTypeError)(_messages.THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT);
|
||||
}
|
||||
const species = constructor[_primordials.SymbolSpecies];
|
||||
if (species == null) {
|
||||
return defaultConstructor;
|
||||
}
|
||||
return species;
|
||||
}
|
||||
function IsDetachedBuffer(buffer) {
|
||||
if ((0, _is.isSharedArrayBuffer)(buffer)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
(0, _primordials.ArrayBufferPrototypeSlice)(buffer, 0, 0);
|
||||
return false;
|
||||
} catch (e) {}
|
||||
return true;
|
||||
}
|
||||
function defaultCompare(x, y) {
|
||||
const isXNaN = (0, _primordials.NumberIsNaN)(x);
|
||||
const isYNaN = (0, _primordials.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 = (0, _primordials.ObjectIs)(x, 0);
|
||||
const isYPlusZero = (0, _primordials.ObjectIs)(y, 0);
|
||||
if (!isXPlusZero && isYPlusZero) {
|
||||
return -1;
|
||||
}
|
||||
if (isXPlusZero && !isYPlusZero) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
node_modules/@petamoriken/float16/lib/f16round.cjs
generated
vendored
Normal file
10
node_modules/@petamoriken/float16/lib/f16round.cjs
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.f16round = f16round;
|
||||
var _converter = require("./_util/converter.cjs");
|
||||
function f16round(x) {
|
||||
return (0, _converter.roundToFloat16)(x);
|
||||
}
|
||||
16
node_modules/@petamoriken/float16/lib/index.cjs
generated
vendored
Normal file
16
node_modules/@petamoriken/float16/lib/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var _Float16Array = require("./Float16Array.cjs");
|
||||
exports.Float16Array = _Float16Array.Float16Array;
|
||||
exports.isFloat16Array = _Float16Array.isFloat16Array;
|
||||
var _isTypedArray = require("./isTypedArray.cjs");
|
||||
exports.isTypedArray = _isTypedArray.isTypedArray;
|
||||
var _DataView = require("./DataView.cjs");
|
||||
exports.getFloat16 = _DataView.getFloat16;
|
||||
exports.setFloat16 = _DataView.setFloat16;
|
||||
var _f16round = require("./f16round.cjs");
|
||||
exports.f16round = _f16round.f16round;
|
||||
exports.hfround = _f16round.f16round;
|
||||
11
node_modules/@petamoriken/float16/lib/isTypedArray.cjs
generated
vendored
Normal file
11
node_modules/@petamoriken/float16/lib/isTypedArray.cjs
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isTypedArray = isTypedArray;
|
||||
var _Float16Array = require("./Float16Array.cjs");
|
||||
var _is = require("./_util/is.cjs");
|
||||
function isTypedArray(target) {
|
||||
return (0, _is.isNativeTypedArray)(target) || (0, _Float16Array.isFloat16Array)(target);
|
||||
}
|
||||
101
node_modules/@petamoriken/float16/package.json
generated
vendored
Normal file
101
node_modules/@petamoriken/float16/package.json
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"name": "@petamoriken/float16",
|
||||
"version": "3.8.7",
|
||||
"description": "IEEE 754 half-precision floating-point for JavaScript",
|
||||
"keywords": [
|
||||
"float16",
|
||||
"binary16",
|
||||
"FP16",
|
||||
"half-precision",
|
||||
"ieee754",
|
||||
"Float16Array",
|
||||
"TypedArray",
|
||||
"DataView",
|
||||
"getFloat16",
|
||||
"setFloat16",
|
||||
"f16round",
|
||||
"ponyfill",
|
||||
"shim"
|
||||
],
|
||||
"homepage": "https://github.com/petamoriken/float16",
|
||||
"bugs": {
|
||||
"url": "https://github.com/petamoriken/float16/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/petamoriken/float16.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Kenta Moriuchi <moriken@kimamass.com> (https://moriken.dev)",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./lib/index.cjs",
|
||||
"import": "./src/index.mjs",
|
||||
"types": "./index.d.ts"
|
||||
},
|
||||
"./inspect": {
|
||||
"require": "./inspect/node.cjs",
|
||||
"import": "./inspect/node.mjs"
|
||||
}
|
||||
},
|
||||
"main": "./lib/index.cjs",
|
||||
"browser": "./browser/float16.js",
|
||||
"module": "./src/index.mjs",
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"src",
|
||||
"lib",
|
||||
"browser",
|
||||
"inspect/node.mjs",
|
||||
"inspect/node.cjs",
|
||||
"index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "concurrently \"yarn:build:*\"",
|
||||
"build:browser": "rollup -c",
|
||||
"build:lib": "babel src -d lib --out-file-extension .cjs",
|
||||
"clean": "rm -rf lib browser docs coverage .nyc_output",
|
||||
"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 && 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": "concurrently \"yarn:lint:*\"",
|
||||
"lint:eslint": "eslint src/**/*.mjs",
|
||||
"lint:unused": "find-unused-exports --module-glob 'src/**/*.mjs'",
|
||||
"prepublishOnly": "yarn run lint && yarn test",
|
||||
"refresh": "yarn run clean && yarn run build && yarn run docs",
|
||||
"setup-test-browser": "http-server docs/test -p 8000 > /dev/null 2>&1 &",
|
||||
"test": "mocha test/*.js",
|
||||
"test-browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,firefox_esr,safari,safari_old",
|
||||
"version": "NPM_VERSION_SCRIPT=1 yarn run refresh"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.24.5",
|
||||
"@babel/core": "^7.24.5",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
|
||||
"@types/nightwatch": "^2.3.31",
|
||||
"babel-plugin-replace-import-extension": "^1.1.4",
|
||||
"browserslist": "^4.23.0",
|
||||
"concurrently": "^8.2.2",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-jsdoc": "^48.2.4",
|
||||
"espower-cli": "^1.1.0",
|
||||
"espower-loader": "^1.2.2",
|
||||
"exorcist": "^2.0.0",
|
||||
"find-unused-exports": "^5.0.0",
|
||||
"http-server": "^14.1.1",
|
||||
"mocha": "^10.4.0",
|
||||
"nightwatch": "^3.6.1",
|
||||
"nightwatch-saucelabs-endsauce": "^2.4.0",
|
||||
"nyc": "^15.1.0",
|
||||
"power-assert": "^1.4.2",
|
||||
"rollup": "^4.17.2",
|
||||
"rollup-plugin-cleanup": "^3.2.1",
|
||||
"source-map-support": "^0.5.21"
|
||||
},
|
||||
"packageManager": "yarn@1.22.19"
|
||||
}
|
||||
35
node_modules/@petamoriken/float16/src/DataView.mjs
generated
vendored
Normal file
35
node_modules/@petamoriken/float16/src/DataView.mjs
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import { safeIfNeeded } from "./_util/arrayIterator.mjs";
|
||||
import { convertToNumber, roundToFloat16Bits } from "./_util/converter.mjs";
|
||||
import {
|
||||
DataViewPrototypeGetUint16,
|
||||
DataViewPrototypeSetUint16,
|
||||
} from "./_util/primordials.mjs";
|
||||
|
||||
/**
|
||||
* returns an unsigned 16-bit float at the specified byte offset from the start of the DataView
|
||||
* @param {DataView} dataView
|
||||
* @param {number} byteOffset
|
||||
* @param {[boolean]} opts
|
||||
* @returns {number}
|
||||
*/
|
||||
export function getFloat16(dataView, byteOffset, ...opts) {
|
||||
return convertToNumber(
|
||||
DataViewPrototypeGetUint16(dataView, byteOffset, ...safeIfNeeded(opts))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* stores an unsigned 16-bit float value at the specified byte offset from the start of the DataView
|
||||
* @param {DataView} dataView
|
||||
* @param {number} byteOffset
|
||||
* @param {number} value
|
||||
* @param {[boolean]} opts
|
||||
*/
|
||||
export function setFloat16(dataView, byteOffset, value, ...opts) {
|
||||
return DataViewPrototypeSetUint16(
|
||||
dataView,
|
||||
byteOffset,
|
||||
roundToFloat16Bits(value),
|
||||
...safeIfNeeded(opts)
|
||||
);
|
||||
}
|
||||
1194
node_modules/@petamoriken/float16/src/Float16Array.mjs
generated
vendored
Normal file
1194
node_modules/@petamoriken/float16/src/Float16Array.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
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;
|
||||
}
|
||||
10
node_modules/@petamoriken/float16/src/f16round.mjs
generated
vendored
Normal file
10
node_modules/@petamoriken/float16/src/f16round.mjs
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { roundToFloat16 } from "./_util/converter.mjs";
|
||||
|
||||
/**
|
||||
* returns the nearest half-precision float representation of a number
|
||||
* @param {number} x
|
||||
* @returns {number}
|
||||
*/
|
||||
export function f16round(x) {
|
||||
return roundToFloat16(x);
|
||||
}
|
||||
6
node_modules/@petamoriken/float16/src/index.mjs
generated
vendored
Normal file
6
node_modules/@petamoriken/float16/src/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/* ignore unused exports */
|
||||
|
||||
export { Float16Array, isFloat16Array } from "./Float16Array.mjs";
|
||||
export { isTypedArray } from "./isTypedArray.mjs";
|
||||
export { getFloat16, setFloat16 } from "./DataView.mjs";
|
||||
export { f16round, f16round as hfround } from "./f16round.mjs";
|
||||
10
node_modules/@petamoriken/float16/src/isTypedArray.mjs
generated
vendored
Normal file
10
node_modules/@petamoriken/float16/src/isTypedArray.mjs
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { isFloat16Array } from "./Float16Array.mjs";
|
||||
import { isNativeTypedArray } from "./_util/is.mjs";
|
||||
|
||||
/**
|
||||
* @param {unknown} target
|
||||
* @returns {value is Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float16Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array}
|
||||
*/
|
||||
export function isTypedArray(target) {
|
||||
return isNativeTypedArray(target) || isFloat16Array(target);
|
||||
}
|
||||
Reference in New Issue
Block a user