本文介绍了术语"BODMAS"是什么意思?意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是BODMAS?为什么在编程中有用?

What is BODMAS and why is it useful in programming?

推荐答案

http://www.easymaths. com/What_on_earth_is_Bodmas.htm :

是(2 + 3)x 5 = 5 x 5 = 25吗?

Is it (2 + 3) x 5 = 5 x 5 = 25 ?

或2 +(3 x 5)= 2 + 15 = 17?

or 2 + (3 x 5) = 2 + 15 = 17 ?

BODMAS可以提供​​帮助,并为我们提供遵循的规则,以便我们始终获得正确的答案:

BODMAS can come to the rescue and give us rules to follow so that we always get the right answer:

(B)球拍(O)销售商(D)ivision(M)复赛(A)目的(S)提速

(B)rackets (O)rder (D)ivision (M)ultiplication (A)ddition (S)ubtraction

根据BODMAS,乘法应始终在加法之前完成,因此,根据BODMAS,17实际上是正确的答案,并且如果您键入2 + 3 x 5,它也将是您的计算器给出的答案.

According to BODMAS, multiplication should always be done before addition, therefore 17 is actually the correct answer according to BODMAS and will also be the answer which your calculator will give if you type in 2 + 3 x 5 .

为什么在编程中有用?不知道,但是我想是因为你可以摆脱一些括号吗?我是一个非常有防御力的程序员,所以我的台词可以像这样:

Why it is useful in programming? No idea, but i assume it's because you can get rid of some brackets? I am a quite defensive programmer, so my lines can look like this:

result = (((i + 4) - (a + b)) * MAGIC_NUMBER) - ANOTHER_MAGIC_NUMBER;

使用BODMAS,您可以使其更清晰一些:

with BODMAS you can make this a bit clearer:

result = (i + 4 - (a + b)) * MAGIC_NUMBER - ANOTHER_MAGIC_NUMBER;

我认为我仍然会使用第一个变体-更多括号,但是那样一来,我不必学习另一条规则,而忘记它并导致那些怪异的难以调试的错误的风险就降低了?

I think i'd still use the first variant - more brackets, but that way i do not have to learn yet another rule and i run into less risk of forgetting it and causing those weird hard to debug errors?

不过只是猜测那一部分.

Just guessing at that part though.

Mike Stone修正了Gaius指出的数学问题

Mike Stone Fixed math as Gaius points out

这篇关于术语"BODMAS"是什么意思?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 07:15