Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
petamoriken committed Jul 30, 2023
1 parent 73fd798 commit 62cc470
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/_util/converter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
ObjectIs,
} from "./primordials.mjs";

const f16MLen = 10;
const f16MMask = 0x3ff;
const f16EMax = 31;
const f16EBias = 15;

// base algorithm: https://github.com/feross/ieee754
// BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource>

Expand All @@ -33,11 +38,6 @@ function roundTiesToEven(num) {
return truncated;
}

const f16EMax = 31;
const f16EBias = 15;
const f16MLen = 10;
const f16MMask = 0x3ff;

/**
* round a number to a half float number bits
* @param {unknown} num - double float
Expand Down Expand Up @@ -132,7 +132,7 @@ for (let i = 1; i < 64; ++i) {
* @returns {number} double float
*/
export function convertToNumber(float16bits) {
const i = float16bits >> 10;
uint32View[0] = mantissaTable[offsetTable[i] + (float16bits & 0x3ff)] + exponentTable[i];
const i = float16bits >> f16MLen;
uint32View[0] = mantissaTable[offsetTable[i] + (float16bits & f16MMask)] + exponentTable[i];
return floatView[0];
}

0 comments on commit 62cc470

Please sign in to comment.