forked from brooke/mandel-6502
whee
This commit is contained in:
parent
a47836a39a
commit
8044dbfc21
2 changed files with 27 additions and 17 deletions
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…
Add table
Add a link
Reference in a new issue