This commit is contained in:
Brooke Vibber 2023-01-07 21:19:40 -08:00
commit c5a62cfa1d
3 changed files with 95 additions and 5 deletions

View file

@ -17,11 +17,11 @@ let bytes = Math.ceil(bits / 8) * entries;
let epsilonBits = 1 ;
let epsilon = 2 ** epsilonBits;
function toFixed(float) {
export function toFixed(float) {
return Math.round(float * base);
}
function toFloat(fixed) {
export function toFloat(fixed) {
return fixed / base;
}
@ -48,12 +48,12 @@ for (let i = 0; i < entries * 2; i++) {
// returns fixed point
function log2(fixed) {
export function log2(fixed) {
return enloggen[toIndex(fixed)];
}
// returns rounded integer
function pow2(fixed) {
export function pow2(fixed) {
let n = toIndex(fixed);
if (n > empower.length) {
n = empower.length - 1;
@ -61,7 +61,7 @@ function pow2(fixed) {
return empower[entries + n];
}
function mul(a, b) {
export function mul(a, b) {
if (a == 0) return 0;
if (b == 0) return 0;
let la = log2(a)|0;
@ -93,6 +93,7 @@ for (let i = 0; i < powEntries; i++) {
}
*/
/*
// now just try multipling numbers
let deltas = 0;
let deltaAvg = 0;
@ -153,3 +154,5 @@ for (let i = 0; i < enloggen.length; i++) {
m = Math.max(m, enloggen[i]);
}
console.log(`max enloggen entry is ${m}`);
*/