Multiplication and division

classic Classic list List threaded Threaded
3 messages Options
bin
Reply | Threaded
Open this post in threaded view
|

Multiplication and division

bin
ScreenTest has been optimized to be instantaneous, but it's very slow to replace Math. VM with my own Math. VM in drawing the roof. I think the problem should be multiplication and division, but I've found a lot of knowledge about multiplication and division on the internet. It involves masking displacement operations. Besides, are there any other better ways to make multiplication and division work faster?
Reply | Threaded
Open this post in threaded view
|

Re: Multiplication and division

cadet1620
Administrator
One quick thing that you can do in Math.divide is to move the recursive calling into another function that does not need to waste time checking for negative arguments
function int divide(int x, int y) {
    var q;
    let q = Math._div(Math.abs(x), Math.abs(y));

    if ((x < 0) = (y < 0)) {    // sign(x) == sign(y)
        return q;
    } else {
        return -q;
    }
}
_div(int x, int y) is the normal recursive divide function.

For Mult(), since you are testing the bits in order, you do not need to call a function to get the 2^n bits. Set mask to 1 and do mask = mask + mask to get the next mask value.
bin
Reply | Threaded
Open this post in threaded view
|

Re: Multiplication and division

bin
This post was updated on .
thank you very much, mark
In accordance with your method to re realize the division and multiplication is really faster.