whee
This commit is contained in:
parent
a47836a39a
commit
8044dbfc21
2 changed files with 27 additions and 17 deletions
18
fixed.js
18
fixed.js
|
@ -4,18 +4,19 @@ let bits = 16;
|
|||
// max Mandelbrot zx/zy addition range prior to checking distance
|
||||
let inputRange = 4;
|
||||
|
||||
// Room to hold power up to -12/+4 for 16-bit mandelbrot
|
||||
let shift = 4;
|
||||
let base = 2 ** (bits - shift);
|
||||
|
||||
//let reduction = 4;
|
||||
let reduction = 0;
|
||||
let roundOffset = (2 ** (reduction - 1)) + 1;
|
||||
|
||||
// Room to hold power up to -12/+4 for 16-bit mandelbrot
|
||||
let shift = 5;
|
||||
let base = 2 ** (bits - shift);
|
||||
|
||||
|
||||
let entries = 2 ** (bits - reduction);
|
||||
let bytes = Math.ceil(bits / 8) * entries;
|
||||
|
||||
// try to keep all but the last few bits semi-accurate
|
||||
let epsilonBits = 1 ;
|
||||
let epsilonBits = 1;
|
||||
let epsilon = 2 ** epsilonBits;
|
||||
|
||||
export function toFixed(float) {
|
||||
|
@ -147,8 +148,6 @@ deltaCount = 0;
|
|||
console.log('done');
|
||||
|
||||
|
||||
console.log(`size of enloggen table: ${entries} entries, ${bytes} bytes`);
|
||||
console.log(`size of empower table: ${entries * 2} entries, ${bytes * 2} bytes`);
|
||||
|
||||
let m = 0;
|
||||
for (let i = 0; i < enloggen.length; i++) {
|
||||
|
@ -157,3 +156,6 @@ for (let i = 0; i < enloggen.length; i++) {
|
|||
console.log(`max enloggen entry is ${m}`);
|
||||
|
||||
*/
|
||||
|
||||
console.log(`size of enloggen table: ${entries} entries, ${bytes} bytes`);
|
||||
console.log(`size of empower table: ${entries * 2} entries, ${bytes * 2} bytes`);
|
||||
|
|
24
sim.js
24
sim.js
|
@ -1,5 +1,13 @@
|
|||
import {toFixed, toFloat, mul} from './fixed.js';
|
||||
import {toFixed, mul} from './fixed.js';
|
||||
|
||||
let toFixedLog = toFixed;
|
||||
|
||||
function toFixed16(val) {
|
||||
// 4.12
|
||||
return Math.round(val * (2 ** 12))
|
||||
}
|
||||
|
||||
let four16 = toFixed16(4);
|
||||
|
||||
function imul(a, b) {
|
||||
return Math.imul(a, b) >> 12;
|
||||
|
@ -25,7 +33,7 @@ function logmul(a, b) {
|
|||
return product;
|
||||
}
|
||||
|
||||
let four = toFixed(4);
|
||||
let fourLog = toFixedLog(4);
|
||||
|
||||
let max = 256;
|
||||
let width = 256;
|
||||
|
@ -146,8 +154,8 @@ function run() {
|
|||
});
|
||||
|
||||
setup('imul', (cx, cy) => {
|
||||
cx = toFixed(cx);
|
||||
cy = toFixed(cy);
|
||||
cx = toFixed16(cx);
|
||||
cy = toFixed16(cy);
|
||||
let zx = 0;
|
||||
let zy = 0;
|
||||
let zx_2 = 0;
|
||||
|
@ -159,7 +167,7 @@ function run() {
|
|||
zx_2 = imul(zx, zx);
|
||||
zy_2 = imul(zy, zy);
|
||||
zx_zy = imul(zx, zy);
|
||||
if (zx_2 + zy_2 >= four) {
|
||||
if (zx_2 + zy_2 >= four16) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -169,8 +177,8 @@ function run() {
|
|||
});
|
||||
|
||||
setup('log', (cx, cy) => {
|
||||
cx = toFixed(cx);
|
||||
cy = toFixed(cy);
|
||||
cx = toFixedLog(cx);
|
||||
cy = toFixedLog(cy);
|
||||
let zx = 0;
|
||||
let zy = 0;
|
||||
let zx_2 = 0;
|
||||
|
@ -182,7 +190,7 @@ function run() {
|
|||
zx_2 = logmul(zx, zx);
|
||||
zy_2 = logmul(zy, zy);
|
||||
zx_zy = logmul(zx, zy);
|
||||
if (zx_2 + zy_2 >= four) {
|
||||
if (zx_2 + zy_2 >= fourLog) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue