woo
This commit is contained in:
parent
49831dc048
commit
d32b630320
1 changed files with 28 additions and 8 deletions
36
silly.js
36
silly.js
|
@ -12,8 +12,10 @@ let shift = 4;
|
|||
let base = 2 ** (powBits - shift);
|
||||
|
||||
// 16-bit lookup table
|
||||
let reduction = 0;
|
||||
|
||||
// 12-bit lookup table
|
||||
let reduction = 4;
|
||||
//let reduction = 4;
|
||||
|
||||
function toFixed(float) {
|
||||
return Math.round(float * base);
|
||||
|
@ -73,21 +75,39 @@ process.exit(1);
|
|||
*/
|
||||
|
||||
// now just try multipling numbers
|
||||
let deltas = 0;
|
||||
let count = 0;
|
||||
let deltaCount = 0;
|
||||
let results = 0;
|
||||
|
||||
function round(n, x) {
|
||||
return Math.round(x * n) / n;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
let a = Math.trunc(Math.random() * logEntries);
|
||||
let b = Math.trunc(Math.random() * logEntries);
|
||||
let expected = a * b;
|
||||
let result = mul(a, b);
|
||||
|
||||
let pExpected = a * b;
|
||||
let p = mul(a, b);
|
||||
|
||||
let delta = Math.abs(p - pExpected);
|
||||
let delta = Math.abs(result - expected);
|
||||
let epsilon = 1;
|
||||
|
||||
if (delta >= epsilon) {
|
||||
let percent = 100 * (delta / pExpected);
|
||||
console.log(`${a} * ${b} = ${pExpected}, but got ${p} delta ${delta} ${Math.round(percent * 100) / 100}%`);
|
||||
let percent = 100 * (delta / expected);
|
||||
//console.log(`${a} * ${b} = ${expected}, but got ${result} delta ${delta} ${Math.round(percent * 100) / 100}%`);
|
||||
deltas += delta;
|
||||
deltaCount++;
|
||||
} else {
|
||||
console.log(`${a} * ${b} = ${p}`);
|
||||
//console.log(`${a} * ${b} = ${result}`);
|
||||
}
|
||||
count++;
|
||||
if (count == 100) {
|
||||
deltaAvg = deltas / deltaCount;
|
||||
console.log(`${count - deltaCount} of ${count} ok -- ${deltaCount} off by avg ${round(10,deltaAvg)})`);
|
||||
count = 0;
|
||||
deltas = 0;
|
||||
deltaCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue