lakutata
Version:
An IoC-based universal application framework.
98 lines (95 loc) • 2.11 kB
JavaScript
function t(t, e, o, l, i) {
let n;
let s;
const a = i * 8 - l - 1;
const h = (1 << a) - 1;
const f = h >> 1;
let w = -7;
let M = o ? i - 1 : 0;
const c = o ? -1 : 1;
let p = t[e + M];
M += c;
n = p & (1 << -w) - 1;
p >>= -w;
w += a;
while (w > 0) {
n = n * 256 + t[e + M];
M += c;
w -= 8;
}
s = n & (1 << -w) - 1;
n >>= -w;
w += l;
while (w > 0) {
s = s * 256 + t[e + M];
M += c;
w -= 8;
}
if (n === 0) {
n = 1 - f;
} else if (n === h) {
return s ? NaN : (p ? -1 : 1) * Infinity;
} else {
s = s + Math.pow(2, l);
n = n - f;
}
return (p ? -1 : 1) * s * Math.pow(2, n - l);
}
function e(t, e, o, l, i, n) {
let s;
let a;
let h;
let f = n * 8 - i - 1;
const w = (1 << f) - 1;
const M = w >> 1;
const c = i === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
let p = l ? 0 : n - 1;
const N = l ? 1 : -1;
const r = e < 0 || e === 0 && 1 / e < 0 ? 1 : 0;
e = Math.abs(e);
if (isNaN(e) || e === Infinity) {
a = isNaN(e) ? 1 : 0;
s = w;
} else {
s = Math.floor(Math.log(e) / Math.LN2);
if (e * (h = Math.pow(2, -s)) < 1) {
s--;
h *= 2;
}
if (s + M >= 1) {
e += c / h;
} else {
e += c * Math.pow(2, 1 - M);
}
if (e * h >= 2) {
s++;
h /= 2;
}
if (s + M >= w) {
a = 0;
s = w;
} else if (s + M >= 1) {
a = (e * h - 1) * Math.pow(2, i);
s = s + M;
} else {
a = e * Math.pow(2, M - 1) * Math.pow(2, i);
s = 0;
}
}
while (i >= 8) {
t[o + p] = a & 255;
p += N;
a /= 256;
i -= 8;
}
s = s << i | a;
f += i;
while (f > 0) {
t[o + p] = s & 255;
p += N;
s /= 256;
f -= 8;
}
t[o + p - N] |= r * 128;
}
export { t as readIEEE754, e as writeIEEE754 };