0

Question

I have a division that is x / 2 and I know that is equivalent to x ⋅ 0.5 or $ \frac{x}{2}\; = x \cdot 0.5 $

  • What is the formula to get the multiplication equivalent of a division?
  • What would be the equivalent of x / 180

So a formula to get the zin this equation, I know x, I know y but I need z.

$$ \frac{x}{y}\; = x \cdot z $$


Context

So I know that $\frac{x}{2}\; = x \cdot 0.5$ on top of my head but I don't know how or what formula to get the $x \cdot 0.5$. So in the example above (and actually what I need know) is to know how I can get a multiplication which the result equals to x / 180. But I just don't wanna know for x / 180 but for I guess that there is a formula to get that, and probably is a silly one but because of my high skills in maths this simple question is to easy for me (being sarcastic).

Use case

I need it for game development (but applies to any software or any computer calculation), simply put: Computer get result from multiplications faster than divisions, in 99% of the time this doesn't matter because anyway the result is really quick, but in some software where performance is a problem (i.e Game Development) ins some scenario may make a difference.

  • 1
    $\frac x2 = x \cdot \frac 12$ and $\frac 12 = 0.5$. Generally, $\frac{x}{y} = x \cdot z$ with $z = 1/y$ (assuming that the denominator is not zero). – Martin R Nov 23 '22 at 08:18
  • So, wait I am very slow in math :D . If it was for a division of 180 it would be. $ \frac{x}{180}; = x \cdot \frac{1}{180}; and \frac{1}{180}; = 0.00555555555555555$? – Federico Baù Nov 23 '22 at 08:25
  • Ohh yes it seems right! ok will u put that in an answer? – Federico Baù Nov 23 '22 at 08:27
  • 1
    Note that many compilers with automatically convert the division by a constant into a multiplication (and with more precision and less error-prone than you can), see for example the discussion at https://stackoverflow.com/q/17883240/1187415. Therefore I would not do such “micro optimisations” unless you are very sure that it affects the performance of your program. – Martin R Nov 23 '22 at 08:29
  • Thanks for the article, I will read that! But yes I know that, in fact my question was related to that (I mean the compiler) but not that I would use it (for the reason u just mentioned it) . But I am curious to make this calculation and I didnt know how to do it. By the way I do it with Javascript and I am not sure is javascript does convert division into multiplication – Federico Baù Nov 23 '22 at 08:33
  • And I see that in the first answer there is actually the formula / solution u gave me :P ``y=1/x; for (int i=0; i<arraySize; i++) { a[i] = b[i] * y; }``` – Federico Baù Nov 23 '22 at 08:35
  • https://stackoverflow.com/questions/10535605 | https://softwareengineering.stackexchange.com/questions/363307 – Federico Baù Nov 23 '22 at 08:42
  • 1
    Does this answer your question? Use division instead of multiplication – From the accepted answer: “Maybe if you're dividing many, many numbers by the same $y$, inverting $y$ first and then doing a bunch of multiplications will save some cycles.” – Martin R Nov 23 '22 at 08:43

0 Answers0