User:ArrowHead294/First 50 purely consistent EDOs by odd limit/Appendix

From Xenharmonic Wiki
Jump to navigation Jump to search

This is the JavaScript code I use to find purely-consistent EDOs by odd limit.

function et_error(interval, et)
{
    return [1200, et * 100].map(x => Math.round(x * 100 * (Math.round(et * Math.log2(interval)) / et - Math.log2(interval))) / 100).concat(Math.round(et * Math.log2(interval)) % et);
}

function min_et(h, max_err_pct, max_edos)
{
    var a = 0, i = 1, j = 0, start = Date.now(), output = new Array();
    h = Math.round(Math.abs(h));
    h = h + 1 - (h % 2);

    while (j <= max_edos)
    {
        a = 1;
        for (var k = 3; k <= h; k += 2)
        {
            if (Math.abs(et_error(k, i)[1]) >= 25)
            {
                a = 0;
            }
        }
        if (a == 1)
        {
            j++;
            console.log(i + " | " + (Date.now() - start)/1000 + "s");
        }
        i++;
    }
}