@petamoriken/float16
Advanced tools
Comparing version 3.3.3 to 3.4.0
@@ -1,2 +0,2 @@ | ||
/*! @petamoriken/float16 v3.3.3 | MIT License - https://git.io/float16 */ | ||
/*! @petamoriken/float16 v3.4.0 | MIT License - https://git.io/float16 */ | ||
@@ -184,3 +184,3 @@ var float16 = (function (exports) { | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is object} | ||
*/ | ||
@@ -315,3 +315,3 @@ function isObject$1(value) { | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is object} | ||
*/ | ||
@@ -324,3 +324,3 @@ | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is object} | ||
*/ | ||
@@ -331,7 +331,6 @@ | ||
} | ||
const toString = Object.prototype.toString; | ||
/** | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is DataView} | ||
*/ | ||
@@ -347,3 +346,3 @@ | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array} | ||
*/ | ||
@@ -356,5 +355,13 @@ | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is Uint16Array} | ||
*/ | ||
function isUint16Array(value) { | ||
return getTypedArrayPrototypeSybolToStringTag.call(value) === "Uint16Array"; | ||
} | ||
/** | ||
* @param {unknown} value | ||
* @returns {value is ArrayBuffer} | ||
*/ | ||
function isArrayBuffer(value) { | ||
@@ -365,3 +372,3 @@ return isObjectLike(value) && toString.call(value) === "[object ArrayBuffer]"; | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is SharedArrayBuffer} | ||
*/ | ||
@@ -374,3 +381,3 @@ | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is Iterable} | ||
*/ | ||
@@ -383,3 +390,3 @@ | ||
* @param {unknown} key | ||
* @returns {boolean} | ||
* @returns {value is string} | ||
*/ | ||
@@ -391,2 +398,4 @@ | ||
const brand = Symbol.for("__Float16Array__"); | ||
const _ = createPrivateStorage(); | ||
@@ -399,4 +408,18 @@ /** | ||
function isFloat16ArrayProxy(target) { | ||
return target instanceof Float16Array && _(target).target !== undefined; | ||
function hasFloat16ArrayBrand(target) { | ||
if (!isObjectLike(target)) { | ||
return false; | ||
} | ||
const constructor = target.constructor; | ||
if (constructor === undefined) { | ||
return false; | ||
} | ||
if (!isObject(constructor)) { | ||
throw TypeError("constructor is not a object"); | ||
} | ||
return Reflect.has(constructor, brand); | ||
} | ||
@@ -409,4 +432,12 @@ /** | ||
function isFloat16Array(target) { | ||
return hasFloat16ArrayBrand(target) && !isTypedArray(target); | ||
} | ||
/** | ||
* @param {unknown} target | ||
* @returns {boolean} | ||
*/ | ||
function isFloat16BitsArray(target) { | ||
return target instanceof Float16Array && _(target).proxy !== undefined; | ||
return hasFloat16ArrayBrand(target) && isUint16Array(target); | ||
} | ||
@@ -425,2 +456,20 @@ /** | ||
/** | ||
* peel off Proxy | ||
* @param {Float16Array} float16 | ||
* @return {Float16Array} | ||
*/ | ||
function getFloat16BitsArrayFromFloat16Array(float16) { | ||
let target = _(float16).target; // from another realm | ||
if (target === undefined) { | ||
const clone = new Float16Array(float16.buffer, float16.byteOffset, float16.length); | ||
target = _(clone).target; | ||
} | ||
return target; | ||
} | ||
/** | ||
* @param {unknown} target | ||
@@ -455,5 +504,6 @@ * @returns {boolean} | ||
apply(func, thisArg, args) { | ||
// peel off proxy | ||
if (isFloat16ArrayProxy(thisArg)) { | ||
return Reflect.apply(func, _(thisArg).target, args); | ||
// peel off Proxy | ||
if (isFloat16Array(thisArg)) { | ||
const target = getFloat16BitsArrayFromFloat16Array(thisArg); | ||
return Reflect.apply(func, target, args); | ||
} | ||
@@ -500,2 +550,6 @@ | ||
const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
/** | ||
* limitation: see README.md for details | ||
*/ | ||
class Float16Array extends Uint16Array { | ||
@@ -507,4 +561,5 @@ /** | ||
// input Float16Array | ||
if (isFloat16ArrayProxy(input)) { | ||
super(_(input).target); // object without ArrayBuffer | ||
if (isFloat16Array(input)) { | ||
// peel off Proxy | ||
super(getFloat16BitsArrayFromFloat16Array(input)); // object without ArrayBuffer | ||
} else if (isObject(input) && !isArrayBuffer(input)) { | ||
@@ -521,3 +576,3 @@ let list; | ||
const BufferConstructor = !isSharedArrayBuffer(buffer) ? SpeciesConstructor(buffer, ArrayBuffer) : ArrayBuffer; | ||
const data = new BufferConstructor(length * Uint16Array.BYTES_PER_ELEMENT); | ||
const data = new BufferConstructor(length * Float16Array.BYTES_PER_ELEMENT); | ||
super(data); // Iterable (Array) | ||
@@ -571,2 +626,3 @@ } else if (isIterable(input)) { | ||
/** | ||
* limitation: `Object.getOwnPropertyNames(Float16Array)` or `Reflect.ownKeys(Float16Array)` include this key | ||
* @see https://tc39.es/ecma262/#sec-%typedarray%.from | ||
@@ -577,2 +633,8 @@ */ | ||
static from(src, ...opts) { | ||
// for optimization | ||
if (isFloat16Array(src) && opts.length === 0) { | ||
const uint16 = new Uint16Array(src.buffer, src.byteOffset, src.length); | ||
return new Float16Array(uint16.slice().buffer); | ||
} | ||
if (opts.length === 0) { | ||
@@ -589,2 +651,3 @@ return new Float16Array(Uint16Array.from(src, roundToFloat16Bits).buffer); | ||
/** | ||
* limitation: `Object.getOwnPropertyNames(Float16Array)` or `Reflect.ownKeys(Float16Array)` include this key | ||
* @see https://tc39.es/ecma262/#sec-%typedarray%.of | ||
@@ -597,5 +660,4 @@ */ | ||
const proxy = new Float16Array(length); | ||
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(proxy); | ||
const float16bitsArray = _(proxy).target; | ||
for (let i = 0; i < length; ++i) { | ||
@@ -676,5 +738,4 @@ float16bitsArray[i] = roundToFloat16Bits(items[i]); | ||
const proxy = new Float16Array(length); | ||
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(proxy); | ||
const float16bitsArray = _(proxy).target; | ||
for (let i = 0; i < length; ++i) { | ||
@@ -910,5 +971,5 @@ const val = convertToNumber(this[i]); | ||
if (isFloat16ArrayProxy(input)) { | ||
const float16bitsArray = _(input).target; | ||
if (isFloat16Array(input)) { | ||
// peel off Proxy | ||
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(input); | ||
super.set(float16bitsArray, targetOffset); | ||
@@ -985,4 +1046,3 @@ return; | ||
const float16bitsArray = uint16.slice(...opts); | ||
const proxy = new Float16Array(float16bitsArray.buffer); | ||
return proxy; | ||
return new Float16Array(float16bitsArray.buffer); | ||
} | ||
@@ -1171,2 +1231,14 @@ | ||
} | ||
/** | ||
* @see https://tc39.es/ecma262/#sec-typedarray.bytes_per_element | ||
*/ | ||
Object.defineProperty(Float16Array, "BYTES_PER_ELEMENT", { | ||
value: Uint16Array.BYTES_PER_ELEMENT | ||
}); | ||
/** | ||
* limitation: It is peaked by `Object.getOwnPropertySymbols(Float16Array)` and `Reflect.ownKeys(Float16Array)` | ||
*/ | ||
Object.defineProperty(Float16Array, brand, {}); | ||
const Float16ArrayPrototype = Float16Array.prototype; | ||
@@ -1185,2 +1257,7 @@ /** | ||
for (const key of Reflect.ownKeys(Float16ArrayPrototype)) { | ||
// constructor is not callable | ||
if (key === "constructor") { | ||
continue; | ||
} | ||
const val = Float16ArrayPrototype[key]; | ||
@@ -1227,2 +1304,3 @@ | ||
exports.hfround = hfround; | ||
exports.isFloat16Array = isFloat16Array; | ||
exports.setFloat16 = setFloat16; | ||
@@ -1229,0 +1307,0 @@ |
@@ -334,2 +334,8 @@ /** | ||
/** | ||
* Returns `true` if the value is a Float16Array instance. | ||
* @since v3.3.4 | ||
*/ | ||
export declare function isFloat16Array(value: unknown): value is Float16Array; | ||
/** | ||
* Gets the Float16 value at the specified byte offset from the start of the view. There is | ||
@@ -336,0 +342,0 @@ * no alignment constraint; multi-byte values may be fetched from any offset. |
@@ -6,3 +6,4 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports.isFloat16Array = isFloat16Array; | ||
exports.Float16Array = void 0; | ||
@@ -19,2 +20,4 @@ var _arrayIterator = require("./helper/arrayIterator.js"); | ||
const brand = Symbol.for("__Float16Array__"); | ||
const _ = (0, _private.createPrivateStorage)(); | ||
@@ -27,4 +30,18 @@ /** | ||
function isFloat16ArrayProxy(target) { | ||
return target instanceof Float16Array && _(target).target !== undefined; | ||
function hasFloat16ArrayBrand(target) { | ||
if (!(0, _is.isObjectLike)(target)) { | ||
return false; | ||
} | ||
const constructor = target.constructor; | ||
if (constructor === undefined) { | ||
return false; | ||
} | ||
if (!(0, _is.isObject)(constructor)) { | ||
throw TypeError("constructor is not a object"); | ||
} | ||
return Reflect.has(constructor, brand); | ||
} | ||
@@ -37,4 +54,13 @@ /** | ||
function isFloat16Array(target) { | ||
return hasFloat16ArrayBrand(target) && !(0, _is.isTypedArray)(target); | ||
} | ||
/** | ||
* @param {unknown} target | ||
* @returns {boolean} | ||
*/ | ||
function isFloat16BitsArray(target) { | ||
return target instanceof Float16Array && _(target).proxy !== undefined; | ||
return hasFloat16ArrayBrand(target) && (0, _is.isUint16Array)(target); | ||
} | ||
@@ -53,2 +79,20 @@ /** | ||
/** | ||
* peel off Proxy | ||
* @param {Float16Array} float16 | ||
* @return {Float16Array} | ||
*/ | ||
function getFloat16BitsArrayFromFloat16Array(float16) { | ||
let target = _(float16).target; // from another realm | ||
if (target === undefined) { | ||
const clone = new Float16Array(float16.buffer, float16.byteOffset, float16.length); | ||
target = _(clone).target; | ||
} | ||
return target; | ||
} | ||
/** | ||
* @param {unknown} target | ||
@@ -83,5 +127,6 @@ * @returns {boolean} | ||
apply(func, thisArg, args) { | ||
// peel off proxy | ||
if (isFloat16ArrayProxy(thisArg)) { | ||
return Reflect.apply(func, _(thisArg).target, args); | ||
// peel off Proxy | ||
if (isFloat16Array(thisArg)) { | ||
const target = getFloat16BitsArrayFromFloat16Array(thisArg); | ||
return Reflect.apply(func, target, args); | ||
} | ||
@@ -128,2 +173,5 @@ | ||
const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
/** | ||
* limitation: see README.md for details | ||
*/ | ||
@@ -136,4 +184,5 @@ class Float16Array extends Uint16Array { | ||
// input Float16Array | ||
if (isFloat16ArrayProxy(input)) { | ||
super(_(input).target); // object without ArrayBuffer | ||
if (isFloat16Array(input)) { | ||
// peel off Proxy | ||
super(getFloat16BitsArrayFromFloat16Array(input)); // object without ArrayBuffer | ||
} else if ((0, _is.isObject)(input) && !(0, _is.isArrayBuffer)(input)) { | ||
@@ -150,3 +199,3 @@ let list; | ||
const BufferConstructor = !(0, _is.isSharedArrayBuffer)(buffer) ? (0, _spec.SpeciesConstructor)(buffer, ArrayBuffer) : ArrayBuffer; | ||
const data = new BufferConstructor(length * Uint16Array.BYTES_PER_ELEMENT); | ||
const data = new BufferConstructor(length * Float16Array.BYTES_PER_ELEMENT); | ||
super(data); // Iterable (Array) | ||
@@ -200,2 +249,3 @@ } else if ((0, _is.isIterable)(input)) { | ||
/** | ||
* limitation: `Object.getOwnPropertyNames(Float16Array)` or `Reflect.ownKeys(Float16Array)` include this key | ||
* @see https://tc39.es/ecma262/#sec-%typedarray%.from | ||
@@ -206,2 +256,8 @@ */ | ||
static from(src, ...opts) { | ||
// for optimization | ||
if (isFloat16Array(src) && opts.length === 0) { | ||
const uint16 = new Uint16Array(src.buffer, src.byteOffset, src.length); | ||
return new Float16Array(uint16.slice().buffer); | ||
} | ||
if (opts.length === 0) { | ||
@@ -218,2 +274,3 @@ return new Float16Array(Uint16Array.from(src, _lib.roundToFloat16Bits).buffer); | ||
/** | ||
* limitation: `Object.getOwnPropertyNames(Float16Array)` or `Reflect.ownKeys(Float16Array)` include this key | ||
* @see https://tc39.es/ecma262/#sec-%typedarray%.of | ||
@@ -226,5 +283,4 @@ */ | ||
const proxy = new Float16Array(length); | ||
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(proxy); | ||
const float16bitsArray = _(proxy).target; | ||
for (let i = 0; i < length; ++i) { | ||
@@ -305,5 +361,4 @@ float16bitsArray[i] = (0, _lib.roundToFloat16Bits)(items[i]); | ||
const proxy = new Float16Array(length); | ||
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(proxy); | ||
const float16bitsArray = _(proxy).target; | ||
for (let i = 0; i < length; ++i) { | ||
@@ -539,5 +594,5 @@ const val = (0, _lib.convertToNumber)(this[i]); | ||
if (isFloat16ArrayProxy(input)) { | ||
const float16bitsArray = _(input).target; | ||
if (isFloat16Array(input)) { | ||
// peel off Proxy | ||
const float16bitsArray = getFloat16BitsArrayFromFloat16Array(input); | ||
super.set(float16bitsArray, targetOffset); | ||
@@ -614,4 +669,3 @@ return; | ||
const float16bitsArray = uint16.slice(...opts); | ||
const proxy = new Float16Array(float16bitsArray.buffer); | ||
return proxy; | ||
return new Float16Array(float16bitsArray.buffer); | ||
} | ||
@@ -800,4 +854,16 @@ | ||
} | ||
/** | ||
* @see https://tc39.es/ecma262/#sec-typedarray.bytes_per_element | ||
*/ | ||
exports.default = Float16Array; | ||
exports.Float16Array = Float16Array; | ||
Object.defineProperty(Float16Array, "BYTES_PER_ELEMENT", { | ||
value: Uint16Array.BYTES_PER_ELEMENT | ||
}); | ||
/** | ||
* limitation: It is peaked by `Object.getOwnPropertySymbols(Float16Array)` and `Reflect.ownKeys(Float16Array)` | ||
*/ | ||
Object.defineProperty(Float16Array, brand, {}); | ||
const Float16ArrayPrototype = Float16Array.prototype; | ||
@@ -816,2 +882,7 @@ /** | ||
for (const key of Reflect.ownKeys(Float16ArrayPrototype)) { | ||
// constructor is not callable | ||
if (key === "constructor") { | ||
continue; | ||
} | ||
const val = Float16ArrayPrototype[key]; | ||
@@ -818,0 +889,0 @@ |
@@ -7,4 +7,6 @@ "use strict"; | ||
exports.isObject = isObject; | ||
exports.isObjectLike = isObjectLike; | ||
exports.isDataView = isDataView; | ||
exports.isTypedArray = isTypedArray; | ||
exports.isUint16Array = isUint16Array; | ||
exports.isArrayBuffer = isArrayBuffer; | ||
@@ -19,3 +21,3 @@ exports.isSharedArrayBuffer = isSharedArrayBuffer; | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is object} | ||
*/ | ||
@@ -27,3 +29,3 @@ function isObject(value) { | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is object} | ||
*/ | ||
@@ -39,3 +41,3 @@ | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is DataView} | ||
*/ | ||
@@ -52,3 +54,3 @@ | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is Uint8Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array|BigUint64Array|BigInt64Array} | ||
*/ | ||
@@ -61,6 +63,15 @@ | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is Uint16Array} | ||
*/ | ||
function isUint16Array(value) { | ||
return getTypedArrayPrototypeSybolToStringTag.call(value) === "Uint16Array"; | ||
} | ||
/** | ||
* @param {unknown} value | ||
* @returns {value is ArrayBuffer} | ||
*/ | ||
function isArrayBuffer(value) { | ||
@@ -71,3 +82,3 @@ return isObjectLike(value) && toString.call(value) === "[object ArrayBuffer]"; | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is SharedArrayBuffer} | ||
*/ | ||
@@ -81,3 +92,3 @@ | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is Iterable} | ||
*/ | ||
@@ -91,3 +102,3 @@ | ||
* @param {unknown} key | ||
* @returns {boolean} | ||
* @returns {value is string} | ||
*/ | ||
@@ -94,0 +105,0 @@ |
@@ -13,3 +13,3 @@ "use strict"; | ||
* @param {unknown} value | ||
* @returns {boolean} | ||
* @returns {value is object} | ||
*/ | ||
@@ -16,0 +16,0 @@ function isObject(value) { |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = hfround; | ||
exports.hfround = hfround; | ||
@@ -9,0 +9,0 @@ var _lib = require("./helper/lib.js"); |
{ | ||
"name": "@petamoriken/float16", | ||
"description": "half precision floating point for JavaScript", | ||
"version": "3.3.3", | ||
"main": "./lib/index.js", | ||
"module": "./src/index.mjs", | ||
"version": "3.4.0", | ||
"main": "./index.js", | ||
"module": "./index.mjs", | ||
"exports": { | ||
"require": "./lib/index.js", | ||
"import": "./src/index.mjs" | ||
"require": "./index.js", | ||
"import": "./index.mjs" | ||
}, | ||
@@ -24,9 +24,8 @@ "types": "index.d.ts", | ||
"files": [ | ||
"package.json", | ||
"README.md", | ||
"LICENSE", | ||
"src", | ||
"index.d.ts", | ||
"lib", | ||
"browser" | ||
"browser", | ||
"index.mjs", | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
@@ -53,3 +52,3 @@ "keywords": [ | ||
"docs:test:dependencies": "cp $(npm root)/mocha/mocha.js $(npm root)/mocha/mocha.css $(npm root)/power-assert/build/power-assert.js docs/test", | ||
"lint": "eslint src/**/*.mjs", | ||
"lint": "eslint *.js src/**/*.mjs test/**/*.js test/**/*.mjs", | ||
"test": "nyc --reporter=lcov mocha", | ||
@@ -56,0 +55,0 @@ "test-browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,firefox_esr,edge,edge_old,safari,safari_old", |
@@ -1,2 +0,2 @@ | ||
# <a href="https://git.io/float16" target="_blank">@petamoriken/float16</a> | ||
# <a href="https://git.io/float16">@petamoriken/float16</a> | ||
@@ -9,12 +9,12 @@ <p align="center"> | ||
<p align="center"> | ||
<a href="https://www.npmjs.com/package/@petamoriken/float16" target="_blank"> | ||
<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" target="_blank"> | ||
<a href="https://www.npmjs.com/package/@petamoriken/float16"> | ||
<img src="https://img.shields.io/npm/v/@petamoriken/float16.svg?label=version&style=flat-square" alt="npm"> | ||
</a> | ||
<a href="https://github.com/petamoriken/float16/blob/master/LICENSE" target="_blank"> | ||
<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" target="_blank"> | ||
<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"> | ||
@@ -25,3 +25,3 @@ </a> | ||
<p align="center"> | ||
<a href="https://saucelabs.com/u/petamoriken" target="_blank"> | ||
<a href="https://saucelabs.com/u/petamoriken"> | ||
<img src="https://saucelabs.com/browser-matrix/petamoriken.svg" alt="Sauce Labs browser matrix"> | ||
@@ -47,3 +47,3 @@ </a> | ||
// ES Modules | ||
import { Float16Array, getFloat16, setFloat16, hfround } from "@petamoriken/float16"; | ||
import { Float16Array, isFloat16Array, getFloat16, setFloat16, hfround } from "@petamoriken/float16"; | ||
``` | ||
@@ -53,3 +53,3 @@ | ||
// CommonJS | ||
const { Float16Array, getFloat16, setFloat16, hfround } = require("@petamoriken/float16"); | ||
const { Float16Array, isFloat16Array, getFloat16, setFloat16, hfround } = require("@petamoriken/float16"); | ||
``` | ||
@@ -64,3 +64,3 @@ | ||
<script type="module"> | ||
import { Float16Array, getFloat16, setFloat16, hfround } from "DEST/TO/float16.mjs"; | ||
import { Float16Array, isFloat16Array, getFloat16, setFloat16, hfround } from "DEST/TO/float16.mjs"; | ||
</script> | ||
@@ -73,3 +73,3 @@ ``` | ||
<script> | ||
const { Float16Array, getFloat16, setFloat16, hfround } = float16; | ||
const { Float16Array, isFloat16Array, getFloat16, setFloat16, hfround } = float16; | ||
</script> | ||
@@ -83,3 +83,3 @@ ``` | ||
<script type="module"> | ||
import { Float16Array, getFloat16, setFloat16, hfround } from "https://cdn.jsdelivr.net/npm/@petamoriken/float16/+esm"; | ||
import { Float16Array, isFloat16Array, getFloat16, setFloat16, hfround } from "https://cdn.jsdelivr.net/npm/@petamoriken/float16/+esm"; | ||
</script> | ||
@@ -92,3 +92,3 @@ ``` | ||
<script> | ||
const { Float16Array, getFloat16, setFloat16, hfround } = float16; | ||
const { Float16Array, isFloat16Array, getFloat16, setFloat16, hfround } = float16; | ||
</script> | ||
@@ -102,10 +102,10 @@ ``` | ||
<script type="module"> | ||
import { Float16Array, getFloat16, setFloat16, hfround } from "https://cdn.skypack.dev/@petamoriken/float16?min"; | ||
import { Float16Array, isFloat16Array, getFloat16, setFloat16, hfround } from "https://cdn.skypack.dev/@petamoriken/float16?min"; | ||
</script> | ||
``` | ||
### Deno (Skypack CDN) | ||
### Deno | ||
```ts | ||
import { Float16Array, getFloat16, setFloat16, hfround } from "https://cdn.skypack.dev/@petamoriken/float16?dts"; | ||
import { Float16Array, isFloat16Array, getFloat16, setFloat16, hfround } from "https://deno.land/x/float16/index.mjs"; | ||
``` | ||
@@ -143,2 +143,14 @@ | ||
### `isFloat16Array` | ||
```ts | ||
declare function isFloat16Array(value: unknown): value is Float16Array; | ||
``` | ||
```js | ||
isFloat16Array(new Float16Array()); // true | ||
isFloat16Array(new Float32Array()); // false | ||
isFloat16Array(new Uint16Array()); // false | ||
``` | ||
### `DataView` | ||
@@ -186,5 +198,5 @@ | ||
### The `instanceof` operator | ||
### The `instanceof` Operator | ||
Since `Float16Array` is made by inheriting from `Uint16Array`, it doesn't work if the `instanceof` operator is used to detect a `Uint16Array`. | ||
Since `Float16Array` is made by inheriting from `Uint16Array`, so you can't use the `instanceof` operator to check if it is a `Uint16Array` or not. | ||
@@ -209,5 +221,5 @@ ```js | ||
For Node.js, you can use `util.types.isUint16Array` ([document](https://nodejs.org/api/util.html#util_util_types_isuint16array_value)) instead. `@@toStringTag` seems to be used for [its implementation](https://github.com/nodejs/node/blob/v16.x/lib/internal/util/types.js). | ||
For Node.js, you can use `util.types` ([document](https://nodejs.org/api/util.html#util_util_types)) instead. Want to do a more solid `TypedArray` check for other environments? Then you can use [this code](https://gist.github.com/petamoriken/6982e7469994a8880bcbef6198203042) 😉 | ||
### Built-in functions | ||
### Built-in Functions | ||
@@ -225,6 +237,2 @@ 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)). | ||
### Prototype methods | ||
Due to implementation reasons, some details of `Float16Array` prototype methods may differ from the ECMAScript specification. See JSDoc comments in `src/Float16Array.mjs` for details. | ||
### WebGL | ||
@@ -253,2 +261,6 @@ | ||
### Others | ||
See JSDoc comments in `src/Float16Array.mjs` for details. If you don't write hacky code, you shouldn't have any problems. | ||
## Build | ||
@@ -255,0 +267,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159079
4463
297