Socket
Socket
Sign inDemoInstall

@petamoriken/float16

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@petamoriken/float16 - npm Package Compare versions

Comparing version 3.4.12 to 3.5.0

35

browser/float16.js

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

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

@@ -375,3 +375,3 @@ const float16 = (function (exports) {

if (!isObject(arrayLike)) {
throw TypeError("this is not a object");
throw TypeError("This is not a object");
}

@@ -390,3 +390,3 @@

if (!isObject(target)) {
throw TypeError("this is not a object");
throw TypeError("This is not a object");
}

@@ -399,3 +399,3 @@

if (!isObject(constructor)) {
throw TypeError("constructor is not a object");
throw TypeError("Constructor is not a object");
}

@@ -489,3 +489,3 @@

if (!isObject(constructor)) {
throw TypeError("constructor is not a object");
throw TypeError("Constructor is not a object");
}

@@ -532,3 +532,3 @@

if (!isTypedArray(target)) {
throw new TypeError("This is not a TypedArray");
throw new TypeError("SpeciesConstructor didn't return TypedArray");
}

@@ -605,3 +605,3 @@

/** limitation: see README.md for details */
/** limitation: `Object.getPrototypeOf(Float16Array)` returns `Uint16Array` */
class Float16Array extends Uint16Array {

@@ -1101,3 +1101,3 @@

if (targetOffset < 0) {
throw RangeError("offset is out of bounds");
throw RangeError("Offset is out of bounds");
}

@@ -1126,3 +1126,3 @@

if (targetOffset === Infinity || srcLength + targetOffset > targetLength) {
throw RangeError("offset is out of bounds");
throw RangeError("Offset is out of bounds");
}

@@ -1232,7 +1232,8 @@

const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
const uint16 = new Uint16Array(float16bitsArray.buffer, float16bitsArray.byteOffset, float16bitsArray.length);
const subarray = uint16.subarray(...opts);
const uint16Subarray = uint16.subarray(...opts);
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
const array = new Constructor(subarray.buffer, subarray.byteOffset, subarray.length);
const array = new Constructor(uint16Subarray.buffer, uint16Subarray.byteOffset, uint16Subarray.length);
assertSpeciesTypedArray(array);

@@ -1372,2 +1373,5 @@

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

@@ -1380,2 +1384,5 @@ Object.defineProperty(Float16ArrayPrototype, Symbol.iterator, {

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

@@ -1391,3 +1398,3 @@ * returns an unsigned 16-bit float at the specified byte offset from the start of the DataView.

if (!isDataView(dataView)) {
throw new TypeError("First argument to getFloat16 function must be a DataView");
throw new TypeError("First argument to getFloat16 must be a DataView");
}

@@ -1408,3 +1415,3 @@

if (!isDataView(dataView)) {
throw new TypeError("First argument to setFloat16 function must be a DataView");
throw new TypeError("First argument to setFloat16 must be a DataView");
}

@@ -1411,0 +1418,0 @@

2

package.json
{
"name": "@petamoriken/float16",
"version": "3.4.12",
"version": "3.5.0",
"description": "half precision floating point for JavaScript",

@@ -5,0 +5,0 @@ "keywords": [

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

<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 which <code>TypedArray</code> it is, and when using Web standards such as <code>structuredClone</code> and WebGL.</summary>
<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>
### The `instanceof` operator
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.
```js
new Uint16Array(10) instanceof Uint16Array; // true
new Float16Array(10) instanceof Uint16Array; // true
```
Actually, I could use `Proxy`'s `getPrototypeOf` handler to trap it, but that would be too complex and have some limitations.
In addition, it is a bad idea to use `instanceof` to detect the type of `TypedArray`, because it can't be used to detect the type of objects from other Realms, such as iframe and vm. It is recommended to use `Object#toString` or `@@toStringTag` for this purpose.
```js
function isUint16Array(target) {
if (target === null || typeof target !== "object") {
return false;
}
return target[Symbol.toStringTag] === "Uint16Array";
}
```
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

@@ -254,0 +229,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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc