What's the fastest way to divide an integer by 3?

后端 未结 12 2129
天涯浪人
天涯浪人 2020-11-29 03:40
int x = n / 3;  // <-- make this faster

// for instance

int a = n * 3; // <-- normal integer multiplication

int b = (n << 1) + n; // <-- potentiall         


        
12条回答
  •  再見小時候
    2020-11-29 03:50

    See How To Divide By 3 for an extended discussion of more efficiently dividing by 3, focused on doing FPGA arithmetic operations.

    Also relevant:

    • Optimizing integer divisions with Multiply Shift in C#

提交回复
热议问题