什么是3分的一个整数的最快方法? [英] What's the fastest way to divide an integer by 3?

查看:131
本文介绍了什么是3分的一个整数的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  INT X = N / 3; //<  - 使这个速度更快// 例如int类型的= N * 3; //<  - 正常整数乘法INT B =(N<< 1)+ N; //<  - 这可能更快乘法


解决方案

这是最快的,因为编译器会优化它,如果它可以根据输出的处理器。

  int类型的;
INT B:A =一定的价值;
B = A / 3;

int x = n / 3;  // <-- make this faster

// for instance

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

int b = (n << 1) + n; // <-- potentially faster multiplication

解决方案

This is the fastest as the compiler will optimize it if it can depending on the output processor.

int a;
int b;

a = some value;
b = a / 3;

这篇关于什么是3分的一个整数的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆