@petamoriken/float16
Advanced tools
Comparing version 3.8.2 to 3.8.3
@@ -1,2 +0,2 @@ | ||
/*! @petamoriken/float16 v3.8.2 | MIT License - https://github.com/petamoriken/float16 */ | ||
/*! @petamoriken/float16 v3.8.3 | MIT License - https://github.com/petamoriken/float16 */ | ||
@@ -276,2 +276,5 @@ var float16 = (function (exports) { | ||
} | ||
function isAnyArrayBuffer(value) { | ||
return isArrayBuffer(value) || isSharedArrayBuffer(value); | ||
} | ||
function isOrdinaryArray(value) { | ||
@@ -328,7 +331,10 @@ if (!ArrayIsArray(value)) { | ||
function roundTiesToEven(num) { | ||
const mantissaBitLength = 10; | ||
const mantissaMask = 0x3ff; | ||
const exponentMax = 31; | ||
const exponentBias = 15; | ||
function roundToEven(num) { | ||
const truncated = MathTrunc(num); | ||
const isOdd = truncated % 2 !== 0; | ||
const delta = MathAbs(num - truncated); | ||
if (delta > 0.5 || delta === 0.5 && isOdd) { | ||
if (delta > 0.5 || delta === 0.5 && truncated % 2 !== 0) { | ||
return truncated + MathSign(num); | ||
@@ -338,36 +344,31 @@ } | ||
} | ||
const f16EMax = 31; | ||
const f16EBias = 15; | ||
const f16MLen = 10; | ||
const f16MMask = 0x3ff; | ||
function roundToFloat16Bits(num) { | ||
const absNum = MathAbs( (num)); | ||
const absolute = MathAbs( (num)); | ||
const s = (num) < 0 || ObjectIs(num, -0) ? 1 : 0; | ||
let m, e; | ||
if (!NumberIsFinite(absNum)) { | ||
m = NumberIsNaN(absNum) ? 0x200 : 0; | ||
e = f16EMax; | ||
if (!NumberIsFinite(absolute)) { | ||
m = NumberIsNaN(absolute) ? 0x200 : 0; | ||
e = exponentMax; | ||
} else { | ||
let rawE = MathFloor(MathLog2(absNum)); | ||
let rawE = MathFloor(MathLog2(absolute)); | ||
let c = MathPow(2, -rawE); | ||
if (absNum * c < 1) { | ||
if (absolute * c < 1) { | ||
--rawE; | ||
c *= 2; | ||
} | ||
if (absNum * c >= 2) { | ||
} else if (absolute * c >= 2) { | ||
++rawE; | ||
c /= 2; | ||
} | ||
if (rawE + f16EBias >= f16EMax) { | ||
if (rawE + exponentBias >= exponentMax) { | ||
m = 0; | ||
e = f16EMax; | ||
} else if (rawE + f16EBias >= 1) { | ||
m = roundTiesToEven(((absNum * c) - 1) * 0x400) & f16MMask; | ||
e = rawE + f16EBias; | ||
e = exponentMax; | ||
} else if (rawE + exponentBias >= 1) { | ||
m = roundToEven(((absolute * c) - 1) * 0x400); | ||
e = rawE + exponentBias; | ||
} else { | ||
m = roundTiesToEven(absNum * 0x1000000) & f16MMask; | ||
m = roundToEven(absolute * 0x1000000); | ||
e = 0; | ||
} | ||
} | ||
return s << 15 | e << f16MLen | m; | ||
return s << 15 | e << mantissaBitLength | m; | ||
} | ||
@@ -409,4 +410,4 @@ const buffer = new NativeArrayBuffer(4); | ||
function convertToNumber(float16bits) { | ||
const i = float16bits >> 10; | ||
uint32View[0] = mantissaTable[offsetTable[i] + (float16bits & 0x3ff)] + exponentTable[i]; | ||
const i = float16bits >> mantissaBitLength; | ||
uint32View[0] = mantissaTable[offsetTable[i] + (float16bits & mantissaMask)] + exponentTable[i]; | ||
return floatView[0]; | ||
@@ -603,3 +604,3 @@ } | ||
float16bitsArray = ReflectConstruct(NativeUint16Array, [getFloat16BitsArray(input)], new.target); | ||
} else if (isObject(input) && !isArrayBuffer(input)) { | ||
} else if (isObject(input) && !isAnyArrayBuffer(input)) { | ||
let list; | ||
@@ -606,0 +607,0 @@ let length; |
{ | ||
"name": "@petamoriken/float16", | ||
"version": "3.8.2", | ||
"version": "3.8.3", | ||
"description": "IEEE 754 half-precision floating-point for JavaScript", | ||
@@ -76,12 +76,12 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/cli": "^7.22.9", | ||
"@babel/core": "^7.22.9", | ||
"@babel/cli": "^7.22.10", | ||
"@babel/core": "^7.22.10", | ||
"@babel/plugin-transform-modules-commonjs": "^7.22.5", | ||
"@types/nightwatch": "^2.3.24", | ||
"@types/nightwatch": "^2.3.25", | ||
"babel-plugin-replace-import-extension": "^1.1.3", | ||
"browserslist": "^4.21.9", | ||
"concurrently": "^8.2.0", | ||
"eslint": "^8.45.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jsdoc": "^46.4.5", | ||
"eslint": "^8.47.0", | ||
"eslint-plugin-import": "^2.28.0", | ||
"eslint-plugin-jsdoc": "^46.4.6", | ||
"espower-cli": "^1.1.0", | ||
@@ -93,7 +93,7 @@ "espower-loader": "^1.2.2", | ||
"mocha": "^10.2.0", | ||
"nightwatch": "^3.1.1", | ||
"nightwatch": "^3.1.2", | ||
"nightwatch-saucelabs-endsauce": "^2.3.1", | ||
"nyc": "^15.1.0", | ||
"power-assert": "^1.4.2", | ||
"rollup": "^3.26.3", | ||
"rollup": "^3.28.0", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
@@ -100,0 +100,0 @@ "source-map-support": "^0.5.21" |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
236879
6139