int besterror(float[] a, int step, int addmul) {
        int best = best(a, step);
        switch (addmul) {
            case 0:
                for (int i = 0, o = 0; i < dim; i++, o += step) {
                    a[o] -= valuelist[best * dim + i];
                }
                break;
            case 1:
                for (int i = 0, o = 0; i < dim; i++, o += step) {
                    float val = valuelist[best * dim + i];
                    if (val == 0) {
                        a[o] = 0;
                    } else {
                        a[o] /= val;
                    }
                }
                break;
        }
        return (best);
    }