Is MOD operation more CPU intensive than multiplication?

后端 未结 5 746
一向
一向 2021-01-04 05:29

Why is MOD operation more expensive than multiplication by a bit more than a factor of 2? Please be more specific about how CPU perfor

5条回答
  •  旧时难觅i
    2021-01-04 05:47

    Algorithms (processors execute the division and the multiplication by algorithms implemented in gates) for division are more costly than for multiplication. As a matter of fact, some algorithms for division which have a good complexity are using the multiplication as a basic step.

    Even if you use the naive algorithms that are learned in school. They both have the same asymptotic complexity, but the constant for the division is greater (you have to find out the digit and that is not trivial, so you can mess up and have to fix the mess).

提交回复
热议问题