@petamoriken/float16
Advanced tools
Comparing version 1.0.3 to 1.0.4
module.exports = { | ||
// To give you an idea how to override rule options: | ||
parser: "babel-eslint", | ||
parserOptions: { | ||
sourceType: "module" | ||
}, | ||
extends: ["eslint:recommended"], | ||
@@ -5,0 +8,0 @@ env: { |
/** | ||
* @petamoriken/float16 1.0.3 - https://github.com/petamoriken/float16 | ||
* generated at 2017-06-06 19:24 +09:00 | ||
* @petamoriken/float16 1.0.4 - https://github.com/petamoriken/float16 | ||
* generated at 2017-07-22 19:31 +09:00 | ||
* | ||
@@ -9,19 +9,19 @@ * --- | ||
(function (exports) { | ||
var float16 = (function (exports) { | ||
'use strict'; | ||
// ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf | ||
// algorithm: ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf | ||
var buffer = new ArrayBuffer(4); | ||
var floatView = new Float32Array(buffer); | ||
var uint32View = new Uint32Array(buffer); | ||
const buffer = new ArrayBuffer(4); | ||
const floatView = new Float32Array(buffer); | ||
const 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$1 < -27) { | ||
if (e < -27) { | ||
baseTable[i | 0x000] = 0x0000; | ||
@@ -33,12 +33,12 @@ baseTable[i | 0x100] = 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; | ||
} 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$1 <= 15) { | ||
baseTable[i | 0x000] = e$1 + 15 << 10; | ||
baseTable[i | 0x100] = e$1 + 15 << 10 | 0x8000; | ||
} else if (e <= 15) { | ||
baseTable[i | 0x000] = e + 15 << 10; | ||
baseTable[i | 0x100] = e + 15 << 10 | 0x8000; | ||
shiftTable[i | 0x000] = 13; | ||
@@ -48,3 +48,3 @@ shiftTable[i | 0x100] = 13; | ||
// large number (Infinity, -Infinity) | ||
} else if (e$1 < 128) { | ||
} else if (e < 128) { | ||
baseTable[i | 0x000] = 0x7c00; | ||
@@ -71,20 +71,20 @@ baseTable[i | 0x100] = 0xfc00; | ||
var f = uint32View[0]; | ||
var e = f >> 23 & 0x1ff; | ||
const f = uint32View[0]; | ||
const 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 (var _i = 1; _i < 1024; ++_i) { | ||
var m = _i << 13; // zero pad mantissa bits | ||
var _e = 0; // zero exponent | ||
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) { | ||
_e -= 0x00800000; // decrement exponent | ||
e -= 0x00800000; // decrement exponent | ||
m <<= 1; | ||
@@ -94,8 +94,8 @@ } | ||
m &= ~0x00800000; // clear leading 1 bit | ||
_e += 0x38800000; // adjust bias | ||
e += 0x38800000; // adjust bias | ||
mantissaTable[_i] = m | _e; | ||
mantissaTable[i] = m | e; | ||
} | ||
for (var _i2 = 1024; _i2 < 2048; ++_i2) { | ||
mantissaTable[_i2] = 0x38000000 + (_i2 - 1024 << 13); | ||
for (let i = 1024; i < 2048; ++i) { | ||
mantissaTable[i] = 0x38000000 + (i - 1024 << 13); | ||
} | ||
@@ -105,9 +105,9 @@ | ||
exponentTable[0] = 0; | ||
for (var _i3 = 1; _i3 < 31; ++_i3) { | ||
exponentTable[_i3] = _i3 << 23; | ||
for (let i = 1; i < 31; ++i) { | ||
exponentTable[i] = i << 23; | ||
} | ||
exponentTable[31] = 0x47800000; | ||
exponentTable[32] = 0x80000000; | ||
for (var _i4 = 33; _i4 < 63; ++_i4) { | ||
exponentTable[_i4] = 0x80000000 + (_i4 - 32 << 23); | ||
for (let i = 33; i < 63; ++i) { | ||
exponentTable[i] = 0x80000000 + (i - 32 << 23); | ||
} | ||
@@ -118,7 +118,7 @@ exponentTable[63] = 0xc7800000; | ||
offsetTable[0] = 0; | ||
for (var _i5 = 1; _i5 < 64; ++_i5) { | ||
if (_i5 === 32) { | ||
offsetTable[_i5] = 0; | ||
for (let i = 1; i < 64; ++i) { | ||
if (i === 32) { | ||
offsetTable[i] = 0; | ||
} else { | ||
offsetTable[_i5] = 1024; | ||
offsetTable[i] = 1024; | ||
} | ||
@@ -132,3 +132,3 @@ } | ||
function convertNumber(h) { | ||
var m = h >> 10; | ||
const m = h >> 10; | ||
uint32View[0] = mantissaTable[offsetTable[m] + (h & 0x3ff)] + exponentTable[m]; | ||
@@ -150,6 +150,46 @@ return floatView[0]; | ||
var x16 = roundToFloat16Bits(num); | ||
const x16 = roundToFloat16Bits(num); | ||
return convertNumber(x16); | ||
} | ||
function ToInteger(num) { | ||
if (typeof num !== "number") num = Number(num); | ||
if (Number.isNaN(num)) num = 0; | ||
return Math.trunc(num); | ||
} | ||
function isPlusZero(val) { | ||
return val === 0 && 1 / val === Infinity; | ||
} | ||
function defaultCompareFunction(x, y) { | ||
var _ref = [Number.isNaN(x), Number.isNaN(y)]; | ||
const isNaN_x = _ref[0], | ||
isNaN_y = _ref[1]; | ||
if (isNaN_x && isNaN_y) return 0; | ||
if (isNaN_x) return 1; | ||
if (isNaN_y) return -1; | ||
if (x < y) return -1; | ||
if (x > y) return 1; | ||
if (x === 0 && y === 0) { | ||
var _ref2 = [isPlusZero(x), isPlusZero(y)]; | ||
const isPlusZero_x = _ref2[0], | ||
isPlusZero_y = _ref2[1]; | ||
if (!isPlusZero_x && isPlusZero_y) return -1; | ||
if (isPlusZero_x && !isPlusZero_y) return 1; | ||
} | ||
return 0; | ||
} | ||
/** Detect free variable `global` from Node.js. */ | ||
@@ -347,2 +387,24 @@ var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; | ||
function isDataView(view) { | ||
return view instanceof DataView; | ||
} | ||
function isNumberKey(key) { | ||
return typeof key === "string" && key === ToInteger(key) + ""; | ||
} | ||
function createPrivateStorage() { | ||
const wm = new WeakMap(); | ||
return self => { | ||
let obj = wm.get(self); | ||
if (obj) { | ||
return obj; | ||
} else { | ||
obj = Object.create(null); | ||
wm.set(self, obj); | ||
return obj; | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -411,126 +473,2 @@ * Checks if `value` is the | ||
/** Used as references for various `Number` constants. */ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
/** | ||
* Checks if `value` is a valid array-like length. | ||
* | ||
* **Note:** This method is loosely based on | ||
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. | ||
* @example | ||
* | ||
* _.isLength(3); | ||
* // => true | ||
* | ||
* _.isLength(Number.MIN_VALUE); | ||
* // => false | ||
* | ||
* _.isLength(Infinity); | ||
* // => false | ||
* | ||
* _.isLength('3'); | ||
* // => false | ||
*/ | ||
function isLength(value) { | ||
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; | ||
} | ||
/** | ||
* Checks if `value` is array-like. A value is considered array-like if it's | ||
* not a function and has a `value.length` that's an integer greater than or | ||
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. | ||
* @example | ||
* | ||
* _.isArrayLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLike(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLike('abc'); | ||
* // => true | ||
* | ||
* _.isArrayLike(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLike(value) { | ||
return value != null && isLength(value.length) && !isFunction(value); | ||
} | ||
function isDataView(view) { | ||
return view instanceof DataView; | ||
} | ||
function isNumberKey(key) { | ||
return typeof key === "string" && key === ToInteger(key) + ""; | ||
} | ||
function isPlusZero(val) { | ||
return val === 0 && 1 / val === Infinity; | ||
} | ||
function ToInteger(num) { | ||
if (typeof num !== "number") num = Number(num); | ||
if (Number.isNaN(num)) num = 0; | ||
return Math.trunc(num); | ||
} | ||
function defaultCompareFunction(x, 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_y) return -1; | ||
if (x < 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; | ||
} | ||
return 0; | ||
} | ||
function createPrivateStorage() { | ||
var wm = new WeakMap(); | ||
return self => { | ||
var obj = wm.get(self); | ||
if (obj) { | ||
return obj; | ||
} else { | ||
obj = Object.create(null); | ||
wm.set(self, obj); | ||
return obj; | ||
} | ||
}; | ||
} | ||
/** Used to detect overreaching core-js shims. */ | ||
@@ -1142,14 +1080,13 @@ var coreJsData = root['__core-js_shared__']; | ||
// 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 | ||
var proxy = new Proxy({}, {}); | ||
var isProxyAbleToBeWeakMapKey = new WeakMap().set(proxy, 1).get(proxy) === 1; | ||
const proxy = new Proxy({}, {}); | ||
const isProxyAbleToBeWeakMapKey = new WeakMap().set(proxy, 1).get(proxy) === 1; | ||
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"); } }; }(); | ||
var _ = createPrivateStorage(); | ||
const _ = createPrivateStorage(); | ||
var __target__ = Symbol("target"); | ||
const __target__ = Symbol("target"); | ||
@@ -1171,6 +1108,6 @@ function isFloat16Array(target) { | ||
function copyToArray(float16bits) { | ||
var length = float16bits.length; | ||
const length = float16bits.length; | ||
var array = new Array(length); | ||
for (var i = 0; i < length; ++i) { | ||
const array = new Array(length); | ||
for (let i = 0; i < length; ++i) { | ||
array[i] = convertNumber(float16bits[i]); | ||
@@ -1183,5 +1120,5 @@ } | ||
// proxy handler | ||
var handler = { | ||
const handler = { | ||
get(target, key) { | ||
var wrapper = null; | ||
let wrapper = null; | ||
if (!isTypedArrayIndexedPropertyWritable) { | ||
@@ -1195,3 +1132,3 @@ wrapper = target; | ||
} else { | ||
var ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key); | ||
const ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key); | ||
@@ -1201,3 +1138,3 @@ if (typeof ret !== "function") return ret; | ||
// TypedArray methods can't be called by Proxy | ||
var proxy = _(ret).proxy; | ||
let proxy = _(ret).proxy; | ||
@@ -1221,3 +1158,3 @@ if (proxy === undefined) { | ||
set(target, key, value) { | ||
var wrapper = null; | ||
let wrapper = null; | ||
if (!isTypedArrayIndexedPropertyWritable) { | ||
@@ -1246,7 +1183,7 @@ wrapper = target; | ||
handler.defineProperty = (wrapper, key, descriptor) => { | ||
var target = _(wrapper).target; | ||
const 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) => { | ||
var target = _(wrapper).target; | ||
const target = _(wrapper).target; | ||
return Reflect.has(wrapper, key) ? Reflect.deleteProperty(wrapper, key) : Reflect.deleteProperty(target, key); | ||
@@ -1275,8 +1212,8 @@ }; | ||
// if input is Iterable, get Array | ||
var array = isArrayLike(input) ? input : [...input]; | ||
const array = input[Symbol.iterator] !== undefined ? [...input] : input; | ||
var _length = array.length; | ||
super(_length); | ||
const length = array.length; | ||
super(length); | ||
for (var i = 0; i < _length; ++i) { | ||
for (let i = 0; i < length; ++i) { | ||
// super (Uint16Array) | ||
@@ -1306,3 +1243,3 @@ this[i] = roundToFloat16Bits(array[i]); | ||
var proxy = void 0; | ||
let proxy; | ||
@@ -1312,3 +1249,3 @@ if (isTypedArrayIndexedPropertyWritable) { | ||
} else { | ||
var wrapper = Object.create(null); | ||
const wrapper = Object.create(null); | ||
_(wrapper).target = this; | ||
@@ -1335,4 +1272,4 @@ proxy = new Proxy(wrapper, handler); | ||
var mapFunc = arguments.length <= 1 ? undefined : arguments[1]; | ||
var thisArg = arguments.length <= 2 ? undefined : arguments[2]; | ||
const mapFunc = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 2 ? undefined : arguments[2]; | ||
@@ -1364,3 +1301,3 @@ return new Float16Array(Uint16Array.from(src, function (val) { | ||
for (var _iterator = super[Symbol.iterator]()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var val = _step.value; | ||
const val = _step.value; | ||
@@ -1396,3 +1333,3 @@ yield convertNumber(val); | ||
for (var _iterator2 = super.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var val = _step2.value; | ||
const val = _step2.value; | ||
@@ -1424,8 +1361,8 @@ yield convertNumber(val); | ||
for (var _iterator3 = super.entries()[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var _ref = _step3.value; | ||
const _ref = _step3.value; | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
var i = _ref2[0]; | ||
var val = _ref2[1]; | ||
const i = _ref2[0]; | ||
const val = _ref2[1]; | ||
@@ -1454,7 +1391,7 @@ yield [i, convertNumber(val)]; | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
var array = []; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
var val = convertNumber(this[i]); | ||
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)); | ||
@@ -1469,7 +1406,7 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
var array = []; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
var val = convertNumber(this[i]); | ||
const array = []; | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
const val = convertNumber(this[i]); | ||
@@ -1485,4 +1422,3 @@ if (callback.call(thisArg, val, i, _(this).proxy)) array.push(val); | ||
var val = void 0, | ||
start = void 0; | ||
let val, start; | ||
@@ -1497,3 +1433,3 @@ if ((arguments.length <= 1 ? 0 : arguments.length - 1) === 0) { | ||
for (var i = start, l = this.length; i < l; ++i) { | ||
for (let i = start, l = this.length; i < l; ++i) { | ||
val = callback(val, convertNumber(this[i]), i, _(this).proxy); | ||
@@ -1508,6 +1444,5 @@ } | ||
var val = void 0, | ||
start = void 0; | ||
let val, start; | ||
var length = this.length; | ||
const length = this.length; | ||
if ((arguments.length <= 1 ? 0 : arguments.length - 1) === 0) { | ||
@@ -1521,3 +1456,3 @@ val = convertNumber(this[length - 1]); | ||
for (var i = start; i--;) { | ||
for (let i = start; i--;) { | ||
val = callback(val, convertNumber(this[i]), i, _(this).proxy); | ||
@@ -1532,5 +1467,5 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
callback.call(thisArg, convertNumber(this[i]), i, _(this).proxy); | ||
@@ -1543,6 +1478,6 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
var value = convertNumber(this[i]); | ||
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; | ||
@@ -1555,6 +1490,6 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
var value = convertNumber(this[i]); | ||
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; | ||
@@ -1569,5 +1504,5 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
if (!callback.call(thisArg, convertNumber(this[i]), i, _(this).proxy)) return false; | ||
@@ -1582,5 +1517,5 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
if (callback.call(thisArg, convertNumber(this[i]), i, _(this).proxy)) return true; | ||
@@ -1596,5 +1531,5 @@ } | ||
var offset = arguments.length <= 1 ? undefined : arguments[1]; | ||
const offset = arguments.length <= 1 ? undefined : arguments[1]; | ||
var float16bits = void 0; | ||
let float16bits; | ||
@@ -1607,7 +1542,7 @@ // input Float16Array | ||
} else { | ||
var array = isArrayLike(input) ? input : [...input]; | ||
var length = array.length; | ||
const array = input[Symbol.iterator] !== undefined ? [...input] : input; | ||
const length = array.length; | ||
float16bits = new Uint16Array(length); | ||
for (var i = 0, l = array.length; i < l; ++i) { | ||
for (let i = 0, l = array.length; i < l; ++i) { | ||
float16bits[i] = roundToFloat16Bits(array[i]); | ||
@@ -1655,3 +1590,3 @@ } | ||
var compareFunction = arguments.length <= 0 ? undefined : arguments[0]; | ||
let compareFunction = arguments.length <= 0 ? undefined : arguments[0]; | ||
@@ -1662,3 +1597,3 @@ if (compareFunction === undefined) { | ||
var _convertNumber = memoize(convertNumber); | ||
const _convertNumber = memoize(convertNumber); | ||
@@ -1674,3 +1609,3 @@ super.sort((x, y) => compareFunction(_convertNumber(x), _convertNumber(y))); | ||
var float16bits = void 0; | ||
let float16bits; | ||
@@ -1682,3 +1617,3 @@ // V8, SpiderMonkey, JavaScriptCore throw TypeError | ||
if (e instanceof TypeError) { | ||
var uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length); | ||
const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length); | ||
float16bits = uint16.slice(...arguments); | ||
@@ -1696,3 +1631,3 @@ } else { | ||
var float16bits = void 0; | ||
let float16bits; | ||
@@ -1704,3 +1639,3 @@ // SpiderMonkey, JavaScriptCore throw TypeError | ||
if (e instanceof TypeError) { | ||
var uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length); | ||
const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length); | ||
float16bits = uint16.subarray(...arguments); | ||
@@ -1719,5 +1654,5 @@ } else { | ||
var length = this.length; | ||
const length = this.length; | ||
var from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]); | ||
let from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]); | ||
@@ -1729,3 +1664,3 @@ if (from < 0) { | ||
for (var i = from, l = length; i < l; ++i) { | ||
for (let i = from, l = length; i < l; ++i) { | ||
if (convertNumber(this[i]) === element) return i; | ||
@@ -1740,5 +1675,5 @@ } | ||
var length = this.length; | ||
const length = this.length; | ||
var from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]); | ||
let from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]); | ||
@@ -1753,3 +1688,3 @@ from = from === 0 ? length : from + 1; | ||
for (var i = from; i--;) { | ||
for (let i = from; i--;) { | ||
if (convertNumber(this[i]) === element) return i; | ||
@@ -1764,5 +1699,5 @@ } | ||
var length = this.length; | ||
const length = this.length; | ||
var from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]); | ||
let from = ToInteger(arguments.length <= 1 ? undefined : arguments[1]); | ||
@@ -1774,5 +1709,5 @@ if (from < 0) { | ||
var isNaN = Number.isNaN(element); | ||
for (var i = from, l = length; i < l; ++i) { | ||
var value = convertNumber(this[i]); | ||
const isNaN = Number.isNaN(element); | ||
for (let i = from, l = length; i < l; ++i) { | ||
const value = convertNumber(this[i]); | ||
@@ -1791,3 +1726,3 @@ if (isNaN && Number.isNaN(value)) return true; | ||
var array = copyToArray(this); | ||
const array = copyToArray(this); | ||
@@ -1800,3 +1735,3 @@ return array.join(...arguments); | ||
var array = copyToArray(this); | ||
const array = copyToArray(this); | ||
@@ -1812,5 +1747,5 @@ return array.toLocaleString(...arguments); | ||
var Float16Array$prototype = Float16Array.prototype; | ||
const Float16Array$prototype = Float16Array.prototype; | ||
var defaultFloat16ArrayMethods = new WeakSet(); | ||
const defaultFloat16ArrayMethods = new WeakSet(); | ||
var _iteratorNormalCompletion4 = true; | ||
@@ -1822,5 +1757,5 @@ var _didIteratorError4 = false; | ||
for (var _iterator4 = Reflect.ownKeys(Float16Array$prototype)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var key = _step4.value; | ||
const key = _step4.value; | ||
var val = Float16Array$prototype[key]; | ||
const val = Float16Array$prototype[key]; | ||
if (typeof val === "function") defaultFloat16ArrayMethods.add(val); | ||
@@ -1881,2 +1816,4 @@ } | ||
}((this.float16 = this.float16 || {}))); | ||
return exports; | ||
}({})); |
"use strict"; | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var isTypedArrayIndexedPropertyWritable = exports.isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable; | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
const isTypedArrayIndexedPropertyWritable = exports.isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable; | ||
// Chakra (Edge <= 14) bug: https://github.com/Microsoft/ChakraCore/issues/1662 | ||
var proxy = new Proxy({}, {}); | ||
var isProxyAbleToBeWeakMapKey = exports.isProxyAbleToBeWeakMapKey = new WeakMap().set(proxy, 1).get(proxy) === 1; | ||
const proxy = new Proxy({}, {}); | ||
const isProxyAbleToBeWeakMapKey = exports.isProxyAbleToBeWeakMapKey = new WeakMap().set(proxy, 1).get(proxy) === 1; |
@@ -27,5 +27,5 @@ "use strict"; | ||
var _ = (0, _private.createPrivateStorage)(); | ||
const _ = (0, _private.createPrivateStorage)(); | ||
var __target__ = Symbol("target"); | ||
const __target__ = Symbol("target"); | ||
@@ -47,6 +47,6 @@ function isFloat16Array(target) { | ||
function copyToArray(float16bits) { | ||
var length = float16bits.length; | ||
const length = float16bits.length; | ||
var array = new Array(length); | ||
for (var i = 0; i < length; ++i) { | ||
const array = new Array(length); | ||
for (let i = 0; i < length; ++i) { | ||
array[i] = (0, _lib.convertNumber)(float16bits[i]); | ||
@@ -59,5 +59,5 @@ } | ||
// proxy handler | ||
var handler = { | ||
const handler = { | ||
get(target, key) { | ||
var wrapper = null; | ||
let wrapper = null; | ||
if (!_bug.isTypedArrayIndexedPropertyWritable) { | ||
@@ -71,3 +71,3 @@ wrapper = target; | ||
} else { | ||
var ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key); | ||
const ret = wrapper !== null && Reflect.has(wrapper, key) ? Reflect.get(wrapper, key) : Reflect.get(target, key); | ||
@@ -77,3 +77,3 @@ if (typeof ret !== "function") return ret; | ||
// TypedArray methods can't be called by Proxy | ||
var proxy = _(ret).proxy; | ||
let proxy = _(ret).proxy; | ||
@@ -97,3 +97,3 @@ if (proxy === undefined) { | ||
set(target, key, value) { | ||
var wrapper = null; | ||
let wrapper = null; | ||
if (!_bug.isTypedArrayIndexedPropertyWritable) { | ||
@@ -122,7 +122,7 @@ wrapper = target; | ||
handler.defineProperty = (wrapper, key, descriptor) => { | ||
var target = _(wrapper).target; | ||
const 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) => { | ||
var target = _(wrapper).target; | ||
const target = _(wrapper).target; | ||
return Reflect.has(wrapper, key) ? Reflect.deleteProperty(wrapper, key) : Reflect.deleteProperty(target, key); | ||
@@ -151,8 +151,8 @@ }; | ||
// if input is Iterable, get Array | ||
var array = (0, _is.isArrayLike)(input) ? input : [...input]; | ||
const array = input[Symbol.iterator] !== undefined ? [...input] : input; | ||
var _length = array.length; | ||
super(_length); | ||
const length = array.length; | ||
super(length); | ||
for (var i = 0; i < _length; ++i) { | ||
for (let i = 0; i < length; ++i) { | ||
// super (Uint16Array) | ||
@@ -182,3 +182,3 @@ this[i] = (0, _lib.roundToFloat16Bits)(array[i]); | ||
var proxy = void 0; | ||
let proxy; | ||
@@ -188,3 +188,3 @@ if (_bug.isTypedArrayIndexedPropertyWritable) { | ||
} else { | ||
var wrapper = Object.create(null); | ||
const wrapper = Object.create(null); | ||
_(wrapper).target = this; | ||
@@ -211,4 +211,4 @@ proxy = new Proxy(wrapper, handler); | ||
var mapFunc = arguments.length <= 1 ? undefined : arguments[1]; | ||
var thisArg = arguments.length <= 2 ? undefined : arguments[2]; | ||
const mapFunc = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 2 ? undefined : arguments[2]; | ||
@@ -240,3 +240,3 @@ return new Float16Array(Uint16Array.from(src, function (val) { | ||
for (var _iterator = super[Symbol.iterator]()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var val = _step.value; | ||
const val = _step.value; | ||
@@ -272,3 +272,3 @@ yield (0, _lib.convertNumber)(val); | ||
for (var _iterator2 = super.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var val = _step2.value; | ||
const val = _step2.value; | ||
@@ -300,8 +300,8 @@ yield (0, _lib.convertNumber)(val); | ||
for (var _iterator3 = super.entries()[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var _ref = _step3.value; | ||
const _ref = _step3.value; | ||
var _ref2 = (0, _slicedToArray3.default)(_ref, 2); | ||
var i = _ref2[0]; | ||
var val = _ref2[1]; | ||
const i = _ref2[0]; | ||
const val = _ref2[1]; | ||
@@ -330,7 +330,7 @@ yield [i, (0, _lib.convertNumber)(val)]; | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
var array = []; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
var val = (0, _lib.convertNumber)(this[i]); | ||
const array = []; | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
const val = (0, _lib.convertNumber)(this[i]); | ||
array.push(callback.call(thisArg, val, i, _(this).proxy)); | ||
@@ -345,7 +345,7 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
var array = []; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
var val = (0, _lib.convertNumber)(this[i]); | ||
const array = []; | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
const val = (0, _lib.convertNumber)(this[i]); | ||
@@ -361,4 +361,3 @@ if (callback.call(thisArg, val, i, _(this).proxy)) array.push(val); | ||
var val = void 0, | ||
start = void 0; | ||
let val, start; | ||
@@ -373,3 +372,3 @@ if ((arguments.length <= 1 ? 0 : arguments.length - 1) === 0) { | ||
for (var i = start, l = this.length; i < l; ++i) { | ||
for (let i = start, l = this.length; i < l; ++i) { | ||
val = callback(val, (0, _lib.convertNumber)(this[i]), i, _(this).proxy); | ||
@@ -384,6 +383,5 @@ } | ||
var val = void 0, | ||
start = void 0; | ||
let val, start; | ||
var length = this.length; | ||
const length = this.length; | ||
if ((arguments.length <= 1 ? 0 : arguments.length - 1) === 0) { | ||
@@ -397,3 +395,3 @@ val = (0, _lib.convertNumber)(this[length - 1]); | ||
for (var i = start; i--;) { | ||
for (let i = start; i--;) { | ||
val = callback(val, (0, _lib.convertNumber)(this[i]), i, _(this).proxy); | ||
@@ -408,5 +406,5 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
callback.call(thisArg, (0, _lib.convertNumber)(this[i]), i, _(this).proxy); | ||
@@ -419,6 +417,6 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
var value = (0, _lib.convertNumber)(this[i]); | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
const value = (0, _lib.convertNumber)(this[i]); | ||
if (callback.call(thisArg, value, i, _(this).proxy)) return value; | ||
@@ -431,6 +429,6 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
var value = (0, _lib.convertNumber)(this[i]); | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
const value = (0, _lib.convertNumber)(this[i]); | ||
if (callback.call(thisArg, value, i, _(this).proxy)) return i; | ||
@@ -445,5 +443,5 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
if (!callback.call(thisArg, (0, _lib.convertNumber)(this[i]), i, _(this).proxy)) return false; | ||
@@ -458,5 +456,5 @@ } | ||
var thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
const thisArg = arguments.length <= 1 ? undefined : arguments[1]; | ||
for (var i = 0, l = this.length; i < l; ++i) { | ||
for (let i = 0, l = this.length; i < l; ++i) { | ||
if (callback.call(thisArg, (0, _lib.convertNumber)(this[i]), i, _(this).proxy)) return true; | ||
@@ -472,5 +470,5 @@ } | ||
var offset = arguments.length <= 1 ? undefined : arguments[1]; | ||
const offset = arguments.length <= 1 ? undefined : arguments[1]; | ||
var float16bits = void 0; | ||
let float16bits; | ||
@@ -483,7 +481,7 @@ // input Float16Array | ||
} else { | ||
var array = (0, _is.isArrayLike)(input) ? input : [...input]; | ||
var length = array.length; | ||
const array = input[Symbol.iterator] !== undefined ? [...input] : input; | ||
const length = array.length; | ||
float16bits = new Uint16Array(length); | ||
for (var i = 0, l = array.length; i < l; ++i) { | ||
for (let i = 0, l = array.length; i < l; ++i) { | ||
float16bits[i] = (0, _lib.roundToFloat16Bits)(array[i]); | ||
@@ -531,3 +529,3 @@ } | ||
var compareFunction = arguments.length <= 0 ? undefined : arguments[0]; | ||
let compareFunction = arguments.length <= 0 ? undefined : arguments[0]; | ||
@@ -538,3 +536,3 @@ if (compareFunction === undefined) { | ||
var _convertNumber = (0, _memoize2.default)(_lib.convertNumber); | ||
const _convertNumber = (0, _memoize2.default)(_lib.convertNumber); | ||
@@ -550,3 +548,3 @@ super.sort((x, y) => compareFunction(_convertNumber(x), _convertNumber(y))); | ||
var float16bits = void 0; | ||
let float16bits; | ||
@@ -558,3 +556,3 @@ // V8, SpiderMonkey, JavaScriptCore throw TypeError | ||
if (e instanceof TypeError) { | ||
var uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length); | ||
const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length); | ||
float16bits = uint16.slice(...arguments); | ||
@@ -572,3 +570,3 @@ } else { | ||
var float16bits = void 0; | ||
let float16bits; | ||
@@ -580,3 +578,3 @@ // SpiderMonkey, JavaScriptCore throw TypeError | ||
if (e instanceof TypeError) { | ||
var uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length); | ||
const uint16 = new Uint16Array(this.buffer, this.byteOffset, this.length); | ||
float16bits = uint16.subarray(...arguments); | ||
@@ -595,5 +593,5 @@ } else { | ||
var length = this.length; | ||
const length = this.length; | ||
var from = (0, _spec.ToInteger)(arguments.length <= 1 ? undefined : arguments[1]); | ||
let from = (0, _spec.ToInteger)(arguments.length <= 1 ? undefined : arguments[1]); | ||
@@ -605,3 +603,3 @@ if (from < 0) { | ||
for (var i = from, l = length; i < l; ++i) { | ||
for (let i = from, l = length; i < l; ++i) { | ||
if ((0, _lib.convertNumber)(this[i]) === element) return i; | ||
@@ -616,5 +614,5 @@ } | ||
var length = this.length; | ||
const length = this.length; | ||
var from = (0, _spec.ToInteger)(arguments.length <= 1 ? undefined : arguments[1]); | ||
let from = (0, _spec.ToInteger)(arguments.length <= 1 ? undefined : arguments[1]); | ||
@@ -629,3 +627,3 @@ from = from === 0 ? length : from + 1; | ||
for (var i = from; i--;) { | ||
for (let i = from; i--;) { | ||
if ((0, _lib.convertNumber)(this[i]) === element) return i; | ||
@@ -640,5 +638,5 @@ } | ||
var length = this.length; | ||
const length = this.length; | ||
var from = (0, _spec.ToInteger)(arguments.length <= 1 ? undefined : arguments[1]); | ||
let from = (0, _spec.ToInteger)(arguments.length <= 1 ? undefined : arguments[1]); | ||
@@ -650,5 +648,5 @@ if (from < 0) { | ||
var isNaN = Number.isNaN(element); | ||
for (var i = from, l = length; i < l; ++i) { | ||
var value = (0, _lib.convertNumber)(this[i]); | ||
const isNaN = Number.isNaN(element); | ||
for (let i = from, l = length; i < l; ++i) { | ||
const value = (0, _lib.convertNumber)(this[i]); | ||
@@ -667,3 +665,3 @@ if (isNaN && Number.isNaN(value)) return true; | ||
var array = copyToArray(this); | ||
const array = copyToArray(this); | ||
@@ -676,3 +674,3 @@ return array.join(...arguments); | ||
var array = copyToArray(this); | ||
const array = copyToArray(this); | ||
@@ -689,5 +687,5 @@ return array.toLocaleString(...arguments); | ||
exports.default = Float16Array; | ||
var Float16Array$prototype = Float16Array.prototype; | ||
const Float16Array$prototype = Float16Array.prototype; | ||
var defaultFloat16ArrayMethods = new WeakSet(); | ||
const defaultFloat16ArrayMethods = new WeakSet(); | ||
var _iteratorNormalCompletion4 = true; | ||
@@ -699,5 +697,5 @@ var _didIteratorError4 = false; | ||
for (var _iterator4 = Reflect.ownKeys(Float16Array$prototype)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var key = _step4.value; | ||
const key = _step4.value; | ||
var val = Float16Array$prototype[key]; | ||
const val = Float16Array$prototype[key]; | ||
if (typeof val === "function") defaultFloat16ArrayMethods.add(val); | ||
@@ -704,0 +702,0 @@ } |
@@ -22,5 +22,5 @@ "use strict"; | ||
var x16 = (0, _lib.roundToFloat16Bits)(num); | ||
const x16 = (0, _lib.roundToFloat16Bits)(num); | ||
return (0, _lib.convertNumber)(x16); | ||
} | ||
module.exports = exports["default"]; |
@@ -6,19 +6,36 @@ "use strict"; | ||
}); | ||
exports.setFloat16 = exports.getFloat16 = exports.Float16Array = exports.hfround = undefined; | ||
var _hfround = require("./hfround"); | ||
var _hfround2 = _interopRequireDefault(_hfround); | ||
Object.defineProperty(exports, "hfround", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_hfround).default; | ||
} | ||
}); | ||
var _Float16Array = require("./Float16Array"); | ||
var _Float16Array2 = _interopRequireDefault(_Float16Array); | ||
Object.defineProperty(exports, "Float16Array", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_Float16Array).default; | ||
} | ||
}); | ||
var _dataView = require("./dataView.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
Object.defineProperty(exports, "getFloat16", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dataView.getFloat16; | ||
} | ||
}); | ||
Object.defineProperty(exports, "setFloat16", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dataView.setFloat16; | ||
} | ||
}); | ||
exports.hfround = _hfround2.default; | ||
exports.Float16Array = _Float16Array2.default; | ||
exports.getFloat16 = _dataView.getFloat16; | ||
exports.setFloat16 = _dataView.setFloat16; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.isArrayLike = exports.isArrayBuffer = undefined; | ||
exports.isArrayBuffer = undefined; | ||
@@ -17,14 +17,4 @@ var _isArrayBuffer = require("lodash/isArrayBuffer"); | ||
}); | ||
var _isArrayLike = require("lodash/isArrayLike"); | ||
Object.defineProperty(exports, "isArrayLike", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_isArrayLike).default; | ||
} | ||
}); | ||
exports.isDataView = isDataView; | ||
exports.isNumberKey = isNumberKey; | ||
exports.isPlusZero = isPlusZero; | ||
@@ -41,6 +31,2 @@ var _spec = require("./spec"); | ||
return typeof key === "string" && key === (0, _spec.ToInteger)(key) + ""; | ||
} | ||
function isPlusZero(val) { | ||
return val === 0 && 1 / val === Infinity; | ||
} |
@@ -1,3 +0,1 @@ | ||
// ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf | ||
"use strict"; | ||
@@ -10,12 +8,14 @@ | ||
exports.convertNumber = convertNumber; | ||
var buffer = new ArrayBuffer(4); | ||
var floatView = new Float32Array(buffer); | ||
var uint32View = new Uint32Array(buffer); | ||
// algorithm: ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf | ||
var baseTable = new Uint32Array(512); | ||
var shiftTable = new Uint32Array(512); | ||
const buffer = new ArrayBuffer(4); | ||
const floatView = new Float32Array(buffer); | ||
const uint32View = new Uint32Array(buffer); | ||
for (var i = 0; i < 256; ++i) { | ||
var e = i - 127; | ||
const baseTable = new Uint32Array(512); | ||
const shiftTable = new Uint32Array(512); | ||
for (let i = 0; i < 256; ++i) { | ||
const e = i - 127; | ||
// very small number (0, -0) | ||
@@ -65,20 +65,20 @@ if (e < -27) { | ||
var f = uint32View[0]; | ||
var e = f >> 23 & 0x1ff; | ||
const f = uint32View[0]; | ||
const 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 (var _i = 1; _i < 1024; ++_i) { | ||
var m = _i << 13; // zero pad mantissa bits | ||
var _e = 0; // zero exponent | ||
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) { | ||
_e -= 0x00800000; // decrement exponent | ||
e -= 0x00800000; // decrement exponent | ||
m <<= 1; | ||
@@ -88,8 +88,8 @@ } | ||
m &= ~0x00800000; // clear leading 1 bit | ||
_e += 0x38800000; // adjust bias | ||
e += 0x38800000; // adjust bias | ||
mantissaTable[_i] = m | _e; | ||
mantissaTable[i] = m | e; | ||
} | ||
for (var _i2 = 1024; _i2 < 2048; ++_i2) { | ||
mantissaTable[_i2] = 0x38000000 + (_i2 - 1024 << 13); | ||
for (let i = 1024; i < 2048; ++i) { | ||
mantissaTable[i] = 0x38000000 + (i - 1024 << 13); | ||
} | ||
@@ -99,9 +99,9 @@ | ||
exponentTable[0] = 0; | ||
for (var _i3 = 1; _i3 < 31; ++_i3) { | ||
exponentTable[_i3] = _i3 << 23; | ||
for (let i = 1; i < 31; ++i) { | ||
exponentTable[i] = i << 23; | ||
} | ||
exponentTable[31] = 0x47800000; | ||
exponentTable[32] = 0x80000000; | ||
for (var _i4 = 33; _i4 < 63; ++_i4) { | ||
exponentTable[_i4] = 0x80000000 + (_i4 - 32 << 23); | ||
for (let i = 33; i < 63; ++i) { | ||
exponentTable[i] = 0x80000000 + (i - 32 << 23); | ||
} | ||
@@ -112,7 +112,7 @@ exponentTable[63] = 0xc7800000; | ||
offsetTable[0] = 0; | ||
for (var _i5 = 1; _i5 < 64; ++_i5) { | ||
if (_i5 === 32) { | ||
offsetTable[_i5] = 0; | ||
for (let i = 1; i < 64; ++i) { | ||
if (i === 32) { | ||
offsetTable[i] = 0; | ||
} else { | ||
offsetTable[_i5] = 1024; | ||
offsetTable[i] = 1024; | ||
} | ||
@@ -126,5 +126,5 @@ } | ||
function convertNumber(h) { | ||
var m = h >> 10; | ||
const m = h >> 10; | ||
uint32View[0] = mantissaTable[offsetTable[m] + (h & 0x3ff)] + exponentTable[m]; | ||
return floatView[0]; | ||
} |
@@ -8,5 +8,5 @@ "use strict"; | ||
function createPrivateStorage() { | ||
var wm = new WeakMap(); | ||
const wm = new WeakMap(); | ||
return self => { | ||
var obj = wm.get(self); | ||
let obj = wm.get(self); | ||
if (obj) { | ||
@@ -13,0 +13,0 @@ return obj; |
@@ -8,5 +8,2 @@ "use strict"; | ||
exports.defaultCompareFunction = defaultCompareFunction; | ||
var _is = require("./is"); | ||
function ToInteger(num) { | ||
@@ -18,6 +15,10 @@ if (typeof num !== "number") num = Number(num); | ||
function isPlusZero(val) { | ||
return val === 0 && 1 / val === Infinity; | ||
} | ||
function defaultCompareFunction(x, y) { | ||
var _ref = [Number.isNaN(x), Number.isNaN(y)], | ||
isNaN_x = _ref[0], | ||
isNaN_y = _ref[1]; | ||
var _ref = [Number.isNaN(x), Number.isNaN(y)]; | ||
const isNaN_x = _ref[0], | ||
isNaN_y = _ref[1]; | ||
@@ -36,5 +37,5 @@ | ||
if (x === 0 && y === 0) { | ||
var _ref2 = [(0, _is.isPlusZero)(x), (0, _is.isPlusZero)(y)], | ||
isPlusZero_x = _ref2[0], | ||
isPlusZero_y = _ref2[1]; | ||
var _ref2 = [isPlusZero(x), isPlusZero(y)]; | ||
const isPlusZero_x = _ref2[0], | ||
isPlusZero_y = _ref2[1]; | ||
@@ -41,0 +42,0 @@ |
{ | ||
"name": "@petamoriken/float16", | ||
"description": "half precision floating point for JavaScript", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "lib/index.js", | ||
@@ -21,2 +21,4 @@ "jsnext:main": "src/index.js", | ||
"LICENSE", | ||
"nightwatch.json", | ||
"nightwatch.conf.js", | ||
"rollup.config.js", | ||
@@ -30,7 +32,9 @@ ".babelrc", | ||
"browser", | ||
"test", | ||
"nightwatch_custom" | ||
"tools", | ||
"docs", | ||
"test" | ||
], | ||
"keywords": [ | ||
"float16", | ||
"binary16", | ||
"half-precision", | ||
@@ -48,6 +52,6 @@ "Float16Array", | ||
"build:browser": "rollup -c", | ||
"docs": "yarn run docs:test", | ||
"docs": "cp README.md docs/index.md && yarn run docs:test", | ||
"docs:test": "cp browser/float16.js docs/test/float16.js && yarn run docs:test:unit && yarn run docs:test:dependencies", | ||
"docs:test:unit": "cp test/*.js docs/test && yarn run docs:test:unit:power", | ||
"docs:test:unit:power": "find test/*.js -execdir bash -c \"eval espower test/{} | exorcist docs/test/power.{}.map > docs/test/power.{}\" \\;", | ||
"docs:test:unit:power": "tools/power", | ||
"docs:test:dependencies": "cp $(npm root)/mocha/mocha.js $(npm root)/mocha/mocha.css $(npm root)/power-assert/build/power-assert.js docs/test", | ||
@@ -57,6 +61,6 @@ "lint": "eslint src", | ||
"test:lib": "mocha", | ||
"test-browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,firefox_esr,edge,safari,safari_el", | ||
"test-browser": "nightwatch -e chrome,chrome_old,firefox,firefox_old,firefox_esr,edge,edge_old,safari,safari_el", | ||
"clean": "rm -rf lib browser docs/test/*.css docs/test/*.js docs/test/*.map", | ||
"refresh": "yarn run clean && yarn run build && yarn run docs", | ||
"prepublish": "in-publish && yarn run clean && yarn run build && yarn test || not-in-publish" | ||
"prepublish": "in-publish && yarn run refresh && yarn test || not-in-publish" | ||
}, | ||
@@ -70,3 +74,3 @@ "devDependencies": { | ||
"babel-preset-env": "^1.4.0", | ||
"eslint": "^3.19.0", | ||
"eslint": "^4.0.0", | ||
"espower-cli": "^1.1.0", | ||
@@ -79,3 +83,3 @@ "exorcist": "^0.4.0", | ||
"power-assert": "^1.4.2", | ||
"rollup": "^0.42.0", | ||
"rollup": "^0.45.1", | ||
"rollup-load-plugins": "^0.3.0", | ||
@@ -82,0 +86,0 @@ "rollup-plugin-babel": "^2.7.1", |
@@ -1,2 +0,2 @@ | ||
# float16 | ||
# float16 <a href="https://github.com/petamoriken/float16" target="_blank"><img src="https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png" width="24" height="24"></a> | ||
@@ -11,5 +11,7 @@ half precision floating point for JavaScript | ||
[![Travis](https://img.shields.io/travis/petamoriken/float16.svg?style=flat-square)](https://travis-ci.org/petamoriken/float16) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/petamoriken/float16.svg?flat-square)](https://greenkeeper.io/) | ||
[![dependencies Status](https://david-dm.org/petamoriken/float16/status.svg?style=flat-square)](https://david-dm.org/petamoriken/float16) | ||
[![devDependencies Status](https://david-dm.org/petamoriken/float16/dev-status.svg?style=flat-square)](https://david-dm.org/petamoriken/float16?type=dev) | ||
[![Sauce Labs browser matrix](https://saucelabs.com/browser-matrix/petamoriken.svg)](https://saucelabs.com/u/petamoriken) | ||
@@ -21,7 +23,5 @@ | ||
The last 2 versions of modern browsers (Chrome, Firefox) and the latest version of default browser on Windows 10 or macOS (Edge, Safari) and Node latest. | ||
* Firefox: last 2 versions and ESR | ||
* Chrome: last 2 versions | ||
* Edge: latest version | ||
* Edge: last 2 versions | ||
* Safari: latest version | ||
@@ -62,3 +62,3 @@ * Node.js: latest version | ||
Copy [the build file for browsers](browser/float16.js) to your project directory. | ||
Copy [the build file for browsers](https://github.com/petamoriken/float16/blob/master/browser/float16.js) to your project directory. | ||
@@ -119,5 +119,25 @@ ```html | ||
## Build | ||
First, download devDependencies. | ||
```console | ||
yarn | ||
``` | ||
Build lib, browser files. | ||
```console | ||
yarn run build | ||
``` | ||
Build docs files (for browser test). | ||
```console | ||
yarn run docs | ||
``` | ||
## Bug | ||
Some browsers have JavaScript bugs. Please see [Float16Array test code](test/Float16Array.js) and search `this.skip()`. | ||
Some browsers have JavaScript bugs. Please see [Float16Array test code](https://github.com/petamoriken/float16/blob/master/test/Float16Array.js) and search `this.skip()`. | ||
@@ -140,6 +160,8 @@ ## Test | ||
Access [test page](https://petamoriken.github.io/float16/test) ([PowerAssert version](https://petamoriken.github.io/float16/test/power)). | ||
Access [test page](https://petamoriken.github.io/float16/test) ([power-assert version](https://petamoriken.github.io/float16/test/power)). | ||
If you want to test in [Sauce Labs](https://saucelabs.com/), export environment variables. | ||
#### Sauce Labs Browser Test | ||
When you want to test in [Sauce Labs](https://saucelabs.com/), export environment variables. | ||
```console | ||
@@ -150,8 +172,14 @@ export SAUCE_USERNAME=<your Sauce Labs username> | ||
(optional) Export a test page URL (default: https://petamoriken.github.io/float16/test/power). | ||
(optional) Export a test page URL (default: `http://localhost:8000/docs/test/power.html`). | ||
```console | ||
export SAUCE_URL=<browser test url> | ||
export TARGET_URL=<browser test url> | ||
``` | ||
If you want to set localhost to `TARGET_URL`, please use [sauce-connect](https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy). | ||
```console | ||
brew cask install sauce-connect | ||
``` | ||
Finally, exec below. | ||
@@ -158,0 +186,0 @@ |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
// JavaScriptCore bug: https://bugs.webkit.org/show_bug.cgi?id=171606 | ||
@@ -4,0 +2,0 @@ export const isTypedArrayIndexedPropertyWritable = Object.getOwnPropertyDescriptor(new Uint8Array(1), 0).writable; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
import { isDataView } from "./is"; | ||
import { roundToFloat16Bits, convertNumber } from "./lib"; | ||
@@ -6,0 +3,0 @@ |
@@ -1,5 +0,3 @@ | ||
"use strict"; | ||
import { ToInteger, defaultCompareFunction } from "./spec"; | ||
import { isNumberKey, isArrayBuffer, isArrayLike } from "./is"; | ||
import { isNumberKey, isArrayBuffer } from "./is"; | ||
import { createPrivateStorage } from "./private"; | ||
@@ -139,3 +137,3 @@ | ||
// if input is Iterable, get Array | ||
const array = isArrayLike(input) ? input : [...input]; | ||
const array = input[Symbol.iterator] !== undefined ? [...input] : input; | ||
@@ -377,3 +375,3 @@ const length = array.length; | ||
} else { | ||
const array = isArrayLike(input) ? input : [...input]; | ||
const array = input[Symbol.iterator] !== undefined ? [...input] : input; | ||
const length = array.length; | ||
@@ -380,0 +378,0 @@ |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
import { roundToFloat16Bits, convertNumber } from "./lib"; | ||
/** | ||
@@ -7,0 +4,0 @@ * returns the nearest half precision float representation of a number. |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
import hfround from "./hfround"; | ||
import Float16Array from "./Float16Array"; | ||
import { getFloat16, setFloat16 } from "./dataView.js"; | ||
export { hfround, Float16Array, getFloat16, setFloat16 }; | ||
export { default as hfround } from "./hfround"; | ||
export { default as Float16Array } from "./Float16Array"; | ||
export { getFloat16, setFloat16 } from "./dataView.js"; |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
import { ToInteger } from "./spec"; | ||
export { default as isArrayBuffer } from "lodash-es/isArrayBuffer"; | ||
export { default as isArrayLike } from "lodash-es/isArrayLike"; | ||
import { ToInteger } from "./spec"; | ||
export function isDataView(view) { | ||
@@ -15,6 +12,2 @@ return view instanceof DataView; | ||
return typeof key === "string" && key === ToInteger(key) + ""; | ||
} | ||
export function isPlusZero(val) { | ||
return val === 0 && 1 / val === Infinity; | ||
} |
@@ -1,5 +0,3 @@ | ||
// ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf | ||
// algorithm: ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf | ||
"use strict"; | ||
const buffer = new ArrayBuffer(4); | ||
@@ -6,0 +4,0 @@ const floatView = new Float32Array(buffer); |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
export function createPrivateStorage() { | ||
@@ -4,0 +2,0 @@ const wm = new WeakMap(); |
@@ -1,5 +0,1 @@ | ||
"use strict"; | ||
import { isPlusZero } from "./is"; | ||
export function ToInteger(num) { | ||
@@ -11,2 +7,6 @@ if(typeof num !== "number") num = Number(num); | ||
function isPlusZero(val) { | ||
return val === 0 && 1 / val === Infinity; | ||
} | ||
export function defaultCompareFunction(x, y) { | ||
@@ -13,0 +13,0 @@ const [isNaN_x, isNaN_y] = [Number.isNaN(x), Number.isNaN(y)]; |
@@ -7,2 +7,5 @@ "use strict"; | ||
// environment | ||
const { TARGET_URL } = process.env; | ||
function asyncElementIdText(client, element) { | ||
@@ -18,4 +21,3 @@ return new Promise(resolve => { | ||
["browser test"](client) { | ||
client.url(process.env.SAUCE_URL || "https://petamoriken.github.io/float16/test/power") | ||
.pause(1000); | ||
client.url(TARGET_URL || "http://localhost:8000/docs/test/power.html").pause(1000); | ||
@@ -45,4 +47,4 @@ client.elements("css selector", "#mocha-report .fail .error", async e => { | ||
client.customSauceEnd(); | ||
setTimeout(done, 1000); | ||
setTimeout(done, 500); | ||
} | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
1610897
53
36631
183
29
3