Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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 1.0.1 to 1.0.2

731

browser/float16.js

@@ -0,1 +1,9 @@

/**
* @petamoriken/float16 1.0.2 - https://github.com/petamoriken/float16
* generated at 2017-05-23 03:29 +09:00
*
* ---
* lodash-es 4.17.4
*/
(function (exports) {

@@ -6,15 +14,14 @@ 'use strict';

const buffer = new ArrayBuffer(4);
const floatView = new Float32Array(buffer);
const uint32View = new Uint32Array(buffer);
var buffer = new ArrayBuffer(4);
var floatView = new Float32Array(buffer);
var uint32View = new Uint32Array(buffer);
var baseTable = new Uint32Array(512);
var shiftTable = new Uint32Array(512);
const baseTable = new Uint32Array(512);
const shiftTable = new Uint32Array(512);
for (var i = 0; i < 256; ++i) {
var e$1 = i - 127;
for(let i = 0; i < 256; ++i) {
const e = i - 127;
// very small number (0, -0)
if(e < -27) {
if (e$1 < -27) {
baseTable[i | 0x000] = 0x0000;

@@ -24,19 +31,19 @@ baseTable[i | 0x100] = 0x8000;

shiftTable[i | 0x100] = 24;
// small number (denorm)
} else if(e < -14) {
baseTable[i | 0x000] = 0x0400 >> (-e - 14);
baseTable[i | 0x100] = (0x0400 >> (-e - 14)) | 0x8000;
shiftTable[i | 0x000] = -e - 1;
shiftTable[i | 0x100] = -e - 1;
// normal number
} else if(e <= 15) {
baseTable[i | 0x000] = (e + 15) << 10;
baseTable[i | 0x100] = ((e + 15) << 10) | 0x8000;
// small number (denorm)
} else if (e$1 < -14) {
baseTable[i | 0x000] = 0x0400 >> -e$1 - 14;
baseTable[i | 0x100] = 0x0400 >> -e$1 - 14 | 0x8000;
shiftTable[i | 0x000] = -e$1 - 1;
shiftTable[i | 0x100] = -e$1 - 1;
// normal number
} else if (e$1 <= 15) {
baseTable[i | 0x000] = e$1 + 15 << 10;
baseTable[i | 0x100] = e$1 + 15 << 10 | 0x8000;
shiftTable[i | 0x000] = 13;
shiftTable[i | 0x100] = 13;
// large number (Infinity, -Infinity)
} else if(e < 128) {
// large number (Infinity, -Infinity)
} else if (e$1 < 128) {
baseTable[i | 0x000] = 0x7c00;

@@ -47,3 +54,3 @@ baseTable[i | 0x100] = 0xfc00;

// stay (NaN, Infinity, -Infinity)
// stay (NaN, Infinity, -Infinity)
} else {

@@ -64,31 +71,30 @@ baseTable[i | 0x000] = 0x7c00;

const f = uint32View[0];
const e = (f >> 23) & 0x1ff;
var f = uint32View[0];
var e = f >> 23 & 0x1ff;
return baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
}
var mantissaTable = new Uint32Array(2048);
var exponentTable = new Uint32Array(64);
var offsetTable = new Uint32Array(64);
const mantissaTable = new Uint32Array(2048);
const exponentTable = new Uint32Array(64);
const offsetTable = new Uint32Array(64);
// mantissa
mantissaTable[0] = 0;
for(let i = 1; i < 1024; ++i) {
let m = i << 13; // zero pad mantissa bits
let e = 0; // zero exponent
for (var _i = 1; _i < 1024; ++_i) {
var m = _i << 13; // zero pad mantissa bits
var _e = 0; // zero exponent
// normalized
while((m & 0x00800000) === 0) {
e -= 0x00800000; // decrement exponent
while ((m & 0x00800000) === 0) {
_e -= 0x00800000; // decrement exponent
m <<= 1;
}
m &= ~0x00800000; // clear leading 1 bit
e += 0x38800000; // adjust bias
m &= ~0x00800000; // clear leading 1 bit
_e += 0x38800000; // adjust bias
mantissaTable[i] = m | e;
mantissaTable[_i] = m | _e;
}
for(let i = 1024; i < 2048; ++i) {
mantissaTable[i] = 0x38000000 + ((i - 1024) << 13);
for (var _i2 = 1024; _i2 < 2048; ++_i2) {
mantissaTable[_i2] = 0x38000000 + (_i2 - 1024 << 13);
}

@@ -98,9 +104,9 @@

exponentTable[0] = 0;
for(let i = 1; i < 31; ++i) {
exponentTable[i] = i << 23;
for (var _i3 = 1; _i3 < 31; ++_i3) {
exponentTable[_i3] = _i3 << 23;
}
exponentTable[31] = 0x47800000;
exponentTable[32] = 0x80000000;
for(let i = 33; i < 63; ++i) {
exponentTable[i] = 0x80000000 + ((i - 32) << 23);
for (var _i4 = 33; _i4 < 63; ++_i4) {
exponentTable[_i4] = 0x80000000 + (_i4 - 32 << 23);
}

@@ -111,7 +117,7 @@ exponentTable[63] = 0xc7800000;

offsetTable[0] = 0;
for(let i = 1; i < 64; ++i) {
if(i === 32) {
offsetTable[i] = 0;
for (var _i5 = 1; _i5 < 64; ++_i5) {
if (_i5 === 32) {
offsetTable[_i5] = 0;
} else {
offsetTable[i] = 1024;
offsetTable[_i5] = 1024;
}

@@ -125,3 +131,3 @@ }

function convertNumber(h) {
const m = h >> 10;
var m = h >> 10;
uint32View[0] = mantissaTable[offsetTable[m] + (h & 0x3ff)] + exponentTable[m];

@@ -139,7 +145,7 @@ return floatView[0];

// for optimization
if(!Number.isFinite(num) || num === 0) {
if (!Number.isFinite(num) || num === 0) {
return num;
}
const x16 = roundToFloat16Bits(num);
var x16 = roundToFloat16Bits(num);
return convertNumber(x16);

@@ -242,5 +248,3 @@ }

}
return (symToStringTag && symToStringTag in Object(value))
? getRawTag(value)
: objectToString(value);
return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
}

@@ -297,3 +301,3 @@

function baseUnary(func) {
return function(value) {
return function (value) {
return func(value);

@@ -316,7 +320,7 @@ };

/** Used to access faster Node.js helpers. */
var nodeUtil = (function() {
var nodeUtil = function () {
try {
return freeProcess && freeProcess.binding && freeProcess.binding('util');
} catch (e) {}
}());
}();

@@ -438,4 +442,3 @@ /* Node.js helper references. */

function isLength(value) {
return typeof value == 'number' &&
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}

@@ -485,4 +488,4 @@

function ToInteger(num) {
if(typeof num !== "number") num = Number(num);
if(Number.isNaN(num)) num = 0;
if (typeof num !== "number") num = Number(num);
if (Number.isNaN(num)) num = 0;
return Math.trunc(num);

@@ -492,27 +495,26 @@ }

function defaultCompareFunction(x, y) {
const [isNaN_x, isNaN_y] = [Number.isNaN(x), Number.isNaN(y)];
var _ref = [Number.isNaN(x), Number.isNaN(y)],
isNaN_x = _ref[0],
isNaN_y = _ref[1];
if(isNaN_x && isNaN_y)
return 0;
if(isNaN_x)
return 1;
if (isNaN_x && isNaN_y) return 0;
if(isNaN_y)
return -1;
if (isNaN_x) return 1;
if(x < y)
return -1;
if (isNaN_y) return -1;
if(x > y)
return 1;
if(x === 0 && y === 0) {
const [isPlusZero_x, isPlusZero_y] = [isPlusZero(x), isPlusZero(y)];
if (x < y) return -1;
if(!isPlusZero_x && isPlusZero_y)
return -1;
if(isPlusZero_x && !isPlusZero_y)
return 1;
if (x > y) return 1;
if (x === 0 && y === 0) {
var _ref2 = [isPlusZero(x), isPlusZero(y)],
isPlusZero_x = _ref2[0],
isPlusZero_y = _ref2[1];
if (!isPlusZero_x && isPlusZero_y) return -1;
if (isPlusZero_x && !isPlusZero_y) return 1;
}

@@ -524,6 +526,6 @@

function createPrivateStorage() {
const wm = new WeakMap();
var wm = new WeakMap();
return self => {
let obj = wm.get(self);
if(obj) {
var obj = wm.get(self);
if (obj) {
return obj;

@@ -535,3 +537,3 @@ } else {

}
}
};
}

@@ -543,6 +545,6 @@

/** Used to detect methods masquerading as native. */
var maskSrcKey = (function() {
var maskSrcKey = function () {
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
return uid ? ('Symbol(src)_1.' + uid) : '';
}());
return uid ? 'Symbol(src)_1.' + uid : '';
}();

@@ -557,3 +559,3 @@ /**

function isMasked(func) {
return !!maskSrcKey && (maskSrcKey in func);
return !!maskSrcKey && maskSrcKey in func;
}

@@ -580,3 +582,3 @@

try {
return (func + '');
return func + '';
} catch (e) {}

@@ -607,6 +609,3 @@ }

/** Used to detect if a method is native. */
var reIsNative = RegExp('^' +
funcToString.call(hasOwnProperty$1).replace(reRegExpChar, '\\$&')
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
);
var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty$1).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');

@@ -729,3 +728,3 @@ /**

var data = this.__data__;
return nativeCreate ? (data[key] !== undefined) : hasOwnProperty$3.call(data, key);
return nativeCreate ? data[key] !== undefined : hasOwnProperty$3.call(data, key);
}

@@ -749,3 +748,3 @@

this.size += this.has(key) ? 0 : 1;
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value;
data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED$1 : value;
return this;

@@ -824,3 +823,3 @@ }

function eq(value, other) {
return value === other || (value !== value && other !== other);
return value === other || value !== value && other !== other;
}

@@ -968,5 +967,5 @@

this.__data__ = {
'hash': new Hash,
'map': new (Map || ListCache),
'string': new Hash
'hash': new Hash(),
'map': new (Map || ListCache)(),
'string': new Hash()
};

@@ -984,5 +983,3 @@ }

var type = typeof value;
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
? (value !== '__proto__')
: (value === null);
return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
}

@@ -1000,5 +997,3 @@

var data = map.__data__;
return isKeyable(key)
? data[typeof key == 'string' ? 'string' : 'hash']
: data.map;
return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
}

@@ -1139,6 +1134,6 @@

function memoize(func, resolver) {
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
if (typeof func != 'function' || resolver != null && typeof resolver != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
var memoized = function() {
var memoized = function memoized() {
var args = arguments,

@@ -1155,3 +1150,3 @@ key = resolver ? resolver.apply(this, args) : args[0],

};
memoized.cache = new (memoize.Cache || MapCache);
memoized.cache = new (memoize.Cache || MapCache)();
return memoized;

@@ -1164,12 +1159,14 @@ }

// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606
const isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable;
var isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable;
// Chakra (Edge <= 14) bug: https://github.com/Microsoft/ChakraCore/issues/1662
const proxy = new Proxy({}, {});
const isProxyAbleToBeWeakMapKey = new WeakMap().set(proxy, 1).get(proxy) === 1;
var proxy = new Proxy({}, {});
var isProxyAbleToBeWeakMapKey = new WeakMap().set(proxy, 1).get(proxy) === 1;
const _ = createPrivateStorage();
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
const __target__ = Symbol("target");
var _ = createPrivateStorage();
var __target__ = Symbol("target");

@@ -1181,3 +1178,3 @@ function isFloat16Array(target) {

function assertFloat16Array(target) {
if(!isFloat16Array(target)) {
if (!isFloat16Array(target)) {
throw new TypeError("This is not a Float16Array");

@@ -1191,8 +1188,7 @@ }

function copyToArray(float16bits) {
const length = float16bits.length;
var length = float16bits.length;
const array = new Array(length);
for(let i = 0; i < length; ++i) {
var array = new Array(length);
for (var i = 0; i < length; ++i) {
array[i] = convertNumber(float16bits[i]);

@@ -1205,6 +1201,6 @@ }

// proxy handler
const handler = {
var handler = {
get(target, key) {
let wrapper = null;
if(!isTypedArrayIndexedPropertyWritable) {
var wrapper = null;
if (!isTypedArrayIndexedPropertyWritable) {
wrapper = target;

@@ -1214,21 +1210,18 @@ target = _(wrapper).target;

if(isNumberKey(key)) {
return convertNumber( Reflect.get(target, key) );
if (isNumberKey(key)) {
return convertNumber(Reflect.get(target, key));
} else {
const ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key);
var ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key);
if(typeof ret !== "function")
return ret;
if (typeof ret !== "function") return ret;
// TypedArray methods can't be called by Proxy
let proxy = _(ret).proxy;
var proxy = _(ret).proxy;
if(proxy === undefined) {
if (proxy === undefined) {
proxy = _(ret).proxy = new Proxy(ret, {
apply(func, thisArg, args) {
// peel off proxy
if(isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func))
return Reflect.apply(func, isProxyAbleToBeWeakMapKey ? _(thisArg).target : thisArg[__target__], args);
if (isFloat16Array(thisArg) && isDefaultFloat16ArrayMethods(func)) return Reflect.apply(func, isProxyAbleToBeWeakMapKey ? _(thisArg).target : thisArg[__target__], args);

@@ -1245,4 +1238,4 @@ return Reflect.apply(func, thisArg, args);

set(target, key, value) {
let wrapper = null;
if(!isTypedArrayIndexedPropertyWritable) {
var wrapper = null;
if (!isTypedArrayIndexedPropertyWritable) {
wrapper = target;

@@ -1252,10 +1245,8 @@ target = _(wrapper).target;

if(isNumberKey(key)) {
if (isNumberKey(key)) {
return Reflect.set(target, key, roundToFloat16Bits(value));
} else {
// frozen object can't change prototype property
if(wrapper !== null && (!Reflect.has(target, key) || Object.isFrozen(wrapper))) {
if (wrapper !== null && (!Reflect.has(target, key) || Object.isFrozen(wrapper))) {
return Reflect.set(wrapper, key, value);
} else {

@@ -1268,25 +1259,24 @@ return Reflect.set(target, key, value);

if(!isTypedArrayIndexedPropertyWritable) {
handler.getPrototypeOf = wrapper => Reflect.getPrototypeOf( _(wrapper).target );
handler.setPrototypeOf = (wrapper, prototype) => Reflect.setPrototypeOf( _(wrapper).target, prototype );
if (!isTypedArrayIndexedPropertyWritable) {
handler.getPrototypeOf = wrapper => Reflect.getPrototypeOf(_(wrapper).target);
handler.setPrototypeOf = (wrapper, prototype) => Reflect.setPrototypeOf(_(wrapper).target, prototype);
handler.defineProperty = (wrapper, key, descriptor) => {
const target = _(wrapper).target;
return !Reflect.has(target, key) || Object.isFrozen(wrapper) ? Reflect.defineProperty( wrapper, key, descriptor ) : Reflect.defineProperty( target, key, descriptor );
var target = _(wrapper).target;
return !Reflect.has(target, key) || Object.isFrozen(wrapper) ? Reflect.defineProperty(wrapper, key, descriptor) : Reflect.defineProperty(target, key, descriptor);
};
handler.deleteProperty = (wrapper, key) => {
const target = _(wrapper).target;
return Reflect.has(wrapper, key) ? Reflect.deleteProperty( wrapper, key ) : Reflect.deleteProperty( target, key );
var target = _(wrapper).target;
return Reflect.has(wrapper, key) ? Reflect.deleteProperty(wrapper, key) : Reflect.deleteProperty(target, key);
};
handler.has = (wrapper, key) => Reflect.has( wrapper, key ) || Reflect.has( _(wrapper).target, key );
handler.isExtensible = wrapper => Reflect.isExtensible( wrapper );
handler.preventExtensions = wrapper => Reflect.preventExtensions( wrapper );
handler.has = (wrapper, key) => Reflect.has(wrapper, key) || Reflect.has(_(wrapper).target, key);
handler.getOwnPropertyDescriptor = (wrapper, key) => Reflect.getOwnPropertyDescriptor( wrapper, key );
handler.ownKeys = wrapper => Reflect.ownKeys( wrapper );
handler.isExtensible = wrapper => Reflect.isExtensible(wrapper);
handler.preventExtensions = wrapper => Reflect.preventExtensions(wrapper);
handler.getOwnPropertyDescriptor = (wrapper, key) => Reflect.getOwnPropertyDescriptor(wrapper, key);
handler.ownKeys = wrapper => Reflect.ownKeys(wrapper);
}
class Float16Array extends Uint16Array {

@@ -1297,33 +1287,33 @@

// input Float16Array
if(isFloat16Array(input)) {
if (isFloat16Array(input)) {
super(isProxyAbleToBeWeakMapKey ? _(input).target : input[__target__]);
// 22.2.1.3, 22.2.1.4 TypedArray, Array, ArrayLike, Iterable
} else if(input !== null && typeof input === "object" && !isArrayBuffer(input)) {
// 22.2.1.3, 22.2.1.4 TypedArray, Array, ArrayLike, Iterable
} else if (input !== null && typeof input === "object" && !isArrayBuffer(input)) {
// if input is Iterable, get Array
const array = isArrayLike(input) ? input : [...input];
const length = array.length;
super(length);
var array = isArrayLike(input) ? input : [...input];
for(let i = 0; i < length; ++i) {
var _length = array.length;
super(_length);
for (var i = 0; i < _length; ++i) {
// super (Uint16Array)
this[i] = roundToFloat16Bits( array[i] );
this[i] = roundToFloat16Bits(array[i]);
}
// 22.2.1.2, 22.2.1.5 primitive, ArrayBuffer
// 22.2.1.2, 22.2.1.5 primitive, ArrayBuffer
} else {
switch(arguments.length) {
switch (arguments.length) {
case 0:
super();
break;
case 1:
super(input);
break;
case 2:
super(input, byteOffset);
break;
default:

@@ -1333,9 +1323,9 @@ super(input, byteOffset, length);

}
let proxy;
if(isTypedArrayIndexedPropertyWritable) {
var proxy = void 0;
if (isTypedArrayIndexedPropertyWritable) {
proxy = new Proxy(this, handler);
} else {
const wrapper = Object.create(null);
var wrapper = Object.create(null);
_(wrapper).target = this;

@@ -1346,3 +1336,3 @@ proxy = new Proxy(wrapper, handler);

// proxy private storage
if(isProxyAbleToBeWeakMapKey) {
if (isProxyAbleToBeWeakMapKey) {
_(proxy).target = this;

@@ -1360,15 +1350,22 @@ } else {

// static methods
static from(src, ...opts) {
if(opts.length === 0)
return new Float16Array( Uint16Array.from(src, roundToFloat16Bits).buffer );
static from(src) {
if ((arguments.length <= 1 ? 0 : arguments.length - 1) === 0) return new Float16Array(Uint16Array.from(src, roundToFloat16Bits).buffer);
const mapFunc = opts[0];
const thisArg = opts[1];
var mapFunc = arguments.length <= 1 ? undefined : arguments[1];
var thisArg = arguments.length <= 2 ? undefined : arguments[2];
return new Float16Array( Uint16Array.from(src, function(val, ...args) {
return roundToFloat16Bits( mapFunc.call(this, val, ...args) );
}, thisArg).buffer );
return new Float16Array(Uint16Array.from(src, function (val) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return roundToFloat16Bits(mapFunc.call(this, val, ...args));
}, thisArg).buffer);
}
static of(...args) {
static of() {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return new Float16Array(args);

@@ -1378,5 +1375,26 @@ }

// iterate methods
* [Symbol.iterator]() {
for(const val of super[Symbol.iterator]()) {
yield convertNumber(val);
*[Symbol.iterator]() {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = super[Symbol.iterator]()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var val = _step.value;
yield convertNumber(val);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

@@ -1389,11 +1407,58 @@ }

* values() {
for(const val of super.values()) {
yield convertNumber(val);
*values() {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = super.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var val = _step2.value;
yield convertNumber(val);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
* entries() {
for(const [i, val] of super.entries()) {
yield [i, convertNumber(val)];
*entries() {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = super.entries()[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _ref = _step3.value;
var _ref2 = _slicedToArray(_ref, 2);
var i = _ref2[0];
var val = _ref2[1];
yield [i, convertNumber(val)];
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}

@@ -1403,11 +1468,11 @@ }

// functional methods
map(callback, ...opts) {
map(callback) {
assertFloat16Array(this);
const thisArg = opts[0];
var thisArg = arguments.length <= 1 ? undefined : arguments[1];
const array = [];
for(let i = 0, l = this.length; i < l; ++i) {
const val = convertNumber(this[i]);
array.push( callback.call(thisArg, val, i, _(this).proxy) );
var array = [];
for (var i = 0, l = this.length; i < l; ++i) {
var val = convertNumber(this[i]);
array.push(callback.call(thisArg, val, i, _(this).proxy));
}

@@ -1418,13 +1483,12 @@

filter(callback, ...opts) {
filter(callback) {
assertFloat16Array(this);
const thisArg = opts[0];
var thisArg = arguments.length <= 1 ? undefined : arguments[1];
const array = [];
for(let i = 0, l = this.length; i < l; ++i) {
const val = convertNumber(this[i]);
var array = [];
for (var i = 0, l = this.length; i < l; ++i) {
var val = convertNumber(this[i]);
if( callback.call(thisArg, val, i, _(this).proxy) )
array.push(val);
if (callback.call(thisArg, val, i, _(this).proxy)) array.push(val);
}

@@ -1435,16 +1499,17 @@

reduce(callback, ...opts) {
reduce(callback) {
assertFloat16Array(this);
let val, start;
var val = void 0,
start = void 0;
if(opts.length === 0) {
if ((arguments.length <= 1 ? 0 : arguments.length - 1) === 0) {
val = convertNumber(this[0]);
start = 1;
} else {
val = opts[0];
val = arguments.length <= 1 ? undefined : arguments[1];
start = 0;
}
for(let i = start, l = this.length; i < l; ++i) {
for (var i = start, l = this.length; i < l; ++i) {
val = callback(val, convertNumber(this[i]), i, _(this).proxy);

@@ -1456,17 +1521,18 @@ }

reduceRight(callback, ...opts) {
reduceRight(callback) {
assertFloat16Array(this);
let val, start;
var val = void 0,
start = void 0;
const length = this.length;
if(opts.length === 0) {
var length = this.length;
if ((arguments.length <= 1 ? 0 : arguments.length - 1) === 0) {
val = convertNumber(this[length - 1]);
start = length - 1;
} else {
val = opts[0];
val = arguments.length <= 1 ? undefined : arguments[1];
start = length;
}
for(let i = start; i--; ) {
for (var i = start; i--;) {
val = callback(val, convertNumber(this[i]), i, _(this).proxy);

@@ -1478,8 +1544,8 @@ }

forEach(callback, ...opts) {
forEach(callback) {
assertFloat16Array(this);
const thisArg = opts[0];
var thisArg = arguments.length <= 1 ? undefined : arguments[1];
for(let i = 0, l = this.length; i < l; ++i) {
for (var i = 0, l = this.length; i < l; ++i) {
callback.call(thisArg, convertNumber(this[i]), i, _(this).proxy);

@@ -1489,21 +1555,21 @@ }

find(callback, ...opts) {
find(callback) {
assertFloat16Array(this);
const thisArg = opts[0];
var thisArg = arguments.length <= 1 ? undefined : arguments[1];
for(let i = 0, l = this.length; i < l; ++i) {
const value = convertNumber(this[i]);
if( callback.call(thisArg, value, i, _(this).proxy) ) return value;
for (var i = 0, l = this.length; i < l; ++i) {
var value = convertNumber(this[i]);
if (callback.call(thisArg, value, i, _(this).proxy)) return value;
}
}
findIndex(callback, ...opts) {
findIndex(callback) {
assertFloat16Array(this);
const thisArg = opts[0];
var thisArg = arguments.length <= 1 ? undefined : arguments[1];
for(let i = 0, l = this.length; i < l; ++i) {
const value = convertNumber(this[i]);
if( callback.call(thisArg, value, i, _(this).proxy) ) return i;
for (var i = 0, l = this.length; i < l; ++i) {
var value = convertNumber(this[i]);
if (callback.call(thisArg, value, i, _(this).proxy)) return i;
}

@@ -1514,9 +1580,9 @@

every(callback, ...opts) {
every(callback) {
assertFloat16Array(this);
const thisArg = opts[0];
var thisArg = arguments.length <= 1 ? undefined : arguments[1];
for(let i = 0, l = this.length; i < l; ++i) {
if( !callback.call(thisArg, convertNumber(this[i]), i, _(this).proxy) ) return false;
for (var i = 0, l = this.length; i < l; ++i) {
if (!callback.call(thisArg, convertNumber(this[i]), i, _(this).proxy)) return false;
}

@@ -1527,9 +1593,9 @@

some(callback, ...opts) {
some(callback) {
assertFloat16Array(this);
const thisArg = opts[0];
for(let i = 0, l = this.length; i < l; ++i) {
if( callback.call(thisArg, convertNumber(this[i]), i, _(this).proxy) ) return true;
var thisArg = arguments.length <= 1 ? undefined : arguments[1];
for (var i = 0, l = this.length; i < l; ++i) {
if (callback.call(thisArg, convertNumber(this[i]), i, _(this).proxy)) return true;
}

@@ -1541,20 +1607,20 @@

// change element methods
set(input, ...opts) {
set(input) {
assertFloat16Array(this);
const offset = opts[0];
var offset = arguments.length <= 1 ? undefined : arguments[1];
let float16bits;
var float16bits = void 0;
// input Float16Array
if(isFloat16Array(input)) {
if (isFloat16Array(input)) {
float16bits = isProxyAbleToBeWeakMapKey ? _(input).target : input[__target__];
// input others
// input others
} else {
const array = isArrayLike(input) ? input : [...input];
const length = array.length;
var array = isArrayLike(input) ? input : [...input];
var length = array.length;
float16bits = new Uint16Array(length);
for(let i = 0, l = array.length; i < l; ++i) {
for (var i = 0, l = array.length; i < l; ++i) {
float16bits[i] = roundToFloat16Bits(array[i]);

@@ -1575,5 +1641,9 @@ }

fill(value, ...opts) {
fill(value) {
assertFloat16Array(this);
for (var _len3 = arguments.length, opts = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
opts[_key3 - 1] = arguments[_key3];
}
super.fill(roundToFloat16Bits(value), ...opts);

@@ -1584,5 +1654,9 @@

copyWithin(target, start, ...opts) {
copyWithin(target, start) {
assertFloat16Array(this);
for (var _len4 = arguments.length, opts = Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
opts[_key4 - 2] = arguments[_key4];
}
super.copyWithin(target, start, ...opts);

@@ -1593,15 +1667,15 @@

sort(...opts) {
sort() {
assertFloat16Array(this);
let compareFunction = opts[0];
var compareFunction = arguments.length <= 0 ? undefined : arguments[0];
if(compareFunction === undefined) {
if (compareFunction === undefined) {
compareFunction = defaultCompareFunction;
}
const _convertNumber = memoize(convertNumber);
var _convertNumber = memoize(convertNumber);
super.sort((x, y) => compareFunction(_convertNumber(x), _convertNumber(y)));
return _(this).proxy;

@@ -1611,14 +1685,14 @@ }

// copy element methods
slice(...opts) {
slice() {
assertFloat16Array(this);
let float16bits;
var float16bits = void 0;
// V8, SpiderMonkey, JavaScriptCore throw TypeError
try {
float16bits = super.slice(...opts);
} catch(e) {
if(e instanceof TypeError) {
const uint16 = new Uint16Array( this.buffer, this.byteOffset, this.length );
float16bits = uint16.slice(...opts);
float16bits = super.slice(...arguments);
} catch (e) {
if (e instanceof TypeError) {
var uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length);
float16bits = uint16.slice(...arguments);
} else {

@@ -1629,17 +1703,17 @@ throw e;

return new Float16Array( float16bits.buffer );
return new Float16Array(float16bits.buffer);
}
subarray(...opts) {
subarray() {
assertFloat16Array(this);
let float16bits;
var float16bits = void 0;
// SpiderMonkey, JavaScriptCore throw TypeError
try {
float16bits = super.subarray(...opts);
} catch(e) {
if(e instanceof TypeError) {
const uint16 = new Uint16Array( this.buffer, this.byteOffset, this.length );
float16bits = uint16.subarray(...opts);
float16bits = super.subarray(...arguments);
} catch (e) {
if (e instanceof TypeError) {
var uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length);
float16bits = uint16.subarray(...arguments);
} else {

@@ -1649,23 +1723,21 @@ throw e;

}
return new Float16Array( float16bits.buffer, float16bits.byteOffset, float16bits.length );
return new Float16Array(float16bits.buffer, float16bits.byteOffset, float16bits.length);
}
// contains methods
indexOf(element, ...opts) {
indexOf(element) {
assertFloat16Array(this);
const length = this.length;
var length = this.length;
let from = ToInteger(opts[0]);
var from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]);
if(from < 0) {
if (from < 0) {
from += length;
if(from < 0)
from = 0;
if (from < 0) from = 0;
}
for(let i = from, l = length; i < l; ++i) {
if(convertNumber(this[i]) === element)
return i;
for (var i = from, l = length; i < l; ++i) {
if (convertNumber(this[i]) === element) return i;
}

@@ -1676,12 +1748,12 @@

lastIndexOf(element, ...opts) {
lastIndexOf(element) {
assertFloat16Array(this);
const length = this.length;
var length = this.length;
let from = ToInteger(opts[0]);
var from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]);
from = from === 0 ? length : from + 1;
if(from >= 0) {
if (from >= 0) {
from = from < length ? from : length;

@@ -1692,5 +1764,4 @@ } else {

for(let i = from; i--; ) {
if(convertNumber(this[i]) === element)
return i;
for (var i = from; i--;) {
if (convertNumber(this[i]) === element) return i;
}

@@ -1701,24 +1772,21 @@

includes(element, ...opts) {
includes(element) {
assertFloat16Array(this);
const length = this.length;
var length = this.length;
let from = ToInteger(opts[0]);
var from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]);
if(from < 0) {
if (from < 0) {
from += length;
if(from < 0)
from = 0;
if (from < 0) from = 0;
}
const isNaN = Number.isNaN(element);
for(let i = from, l = length; i < l; ++i) {
const value = convertNumber(this[i]);
var isNaN = Number.isNaN(element);
for (var i = from, l = length; i < l; ++i) {
var value = convertNumber(this[i]);
if(isNaN && Number.isNaN(value))
return true;
if(value === element)
return true;
if (isNaN && Number.isNaN(value)) return true;
if (value === element) return true;
}

@@ -1730,21 +1798,20 @@

// string methods
join(...opts) {
join() {
assertFloat16Array(this);
const array = copyToArray(this);
var array = copyToArray(this);
return array.join(...opts);
return array.join(...arguments);
}
toLocaleString(...opts) {
toLocaleString() {
assertFloat16Array(this);
const array = copyToArray(this);
var array = copyToArray(this);
return array.toLocaleString(...opts);
return array.toLocaleString(...arguments);
}
get [Symbol.toStringTag]() {
if(isFloat16Array(this))
return "Float16Array";
if (isFloat16Array(this)) return "Float16Array";
}

@@ -1754,9 +1821,29 @@

const Float16Array$prototype = Float16Array.prototype;
var Float16Array$prototype = Float16Array.prototype;
const defaultFloat16ArrayMethods = new WeakSet();
for(const key of Reflect.ownKeys(Float16Array$prototype)) {
const val = Float16Array$prototype[key];
if(typeof val === "function")
defaultFloat16ArrayMethods.add(val);
var defaultFloat16ArrayMethods = new WeakSet();
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = Reflect.ownKeys(Float16Array$prototype)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var key = _step4.value;
var val = Float16Array$prototype[key];
if (typeof val === "function") defaultFloat16ArrayMethods.add(val);
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}

@@ -1770,7 +1857,10 @@

*/
function getFloat16(dataView, byteOffset, ...opts) {
if(!isDataView(dataView))
throw new TypeError("First argument to getFloat16 function must be a DataView");
function getFloat16(dataView, byteOffset) {
if (!isDataView(dataView)) throw new TypeError("First argument to getFloat16 function must be a DataView");
return convertNumber( dataView.getUint16(byteOffset, ...opts) );
for (var _len = arguments.length, opts = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
opts[_key - 2] = arguments[_key];
}
return convertNumber(dataView.getUint16(byteOffset, ...opts));
}

@@ -1785,6 +1875,9 @@

*/
function setFloat16(dataView, byteOffset, value, ...opts) {
if(!isDataView(dataView))
throw new TypeError("First argument to setFloat16 function must be a DataView");
function setFloat16(dataView, byteOffset, value) {
if (!isDataView(dataView)) throw new TypeError("First argument to setFloat16 function must be a DataView");
for (var _len2 = arguments.length, opts = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
opts[_key2 - 3] = arguments[_key2];
}
dataView.setUint16(byteOffset, roundToFloat16Bits(value), ...opts);

@@ -1791,0 +1884,0 @@ }

{
"name": "@petamoriken/float16",
"description": "half precision floating point for JavaScript",
"version": "1.0.1",
"version": "1.0.2",
"main": "lib/index.js",

@@ -54,3 +54,3 @@ "jsnext:main": "src/index.js",

"test:lib": "mocha",
"test-browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,edge,safari,safari_el",
"test-browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,firefox_esr,edge,safari,safari_el",
"clean": "rm -rf lib browser docs/test/*.css docs/test/*.js docs/test/*.map",

@@ -76,2 +76,5 @@ "refresh": "yarn run clean && yarn run build && yarn run docs",

"rollup": "^0.41.6",
"rollup-load-plugins": "^0.3.0",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-license": "^0.4.0",
"rollup-plugin-node-resolve": "^3.0.0",

@@ -78,0 +81,0 @@ "saucelabs": "^1.4.0"

@@ -1,3 +0,13 @@

import nodeResolve from "rollup-plugin-node-resolve";
import loadPlugins from "rollup-load-plugins";
const $ = loadPlugins();
const banner =
`<%= pkg.name %> <%= pkg.version %> - https://github.com/petamoriken/float16
generated at <%= moment().format('YYYY-MM-DD HH:mm Z') %>
---<% _.forEach(dependencies, function (dependency) { %>
<%= dependency.name %> <%= dependency.version %>
<% }) %>`;
export default {

@@ -7,3 +17,14 @@ entry: "src/index.js",

plugins: [
nodeResolve({ browser: true })
$.nodeResolve({ browser: true }),
$.babel({
babelrc: false,
presets: [["env", {
targets: {
browsers: ["last 2 versions", "not ie >= 10", "not android >= 4.4.3", "Firefox ESR"]
},
modules: false,
exclude: ["transform-regenerator"]
}]]
}),
$.license({ banner })
],

@@ -10,0 +31,0 @@ moduleName: "float16",

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