# Multiplication and division

3 messages
Open this post in threaded view
|

## Multiplication and division

 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?
 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.