需要澄清BODMAS规则 [英] need clarification on BODMAS rule

查看:994
本文介绍了需要澄清BODMAS规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在BODMAS规则操作的顺序括号,秩序,除法,乘法加法和除法subtraction.here,乘法,加法和减法是继递减,递增,递增和递减秩序。BODMAS规则系列没有遵循相同的order.And我的问题是为什么加法后跟减法而不是减法随后加入

In BODMAS rule the order of operations are brackets,order,division,multiplication addition and subtraction.here division,multiplication,addition and subtraction is following decrement,increment ,increment and decrement order.the BODMAS rule series is not following the same order.And my question is why addition is followed by subtraction but not subtraction is followed by addition.

推荐答案

BODMAS或BOMDSA是完全一样的,因为乘法/除法和加法/减法处于precedence同一级别(在事实,他们应该是写了正确的 BO DM AS ,与任何命令你各组内preFER);由相关维基百科页面说:

BODMAS or BOMDSA are exactly the same, since multiplication/division and addition/subtraction are at the same level of precedence (in facts, they should be written more correctly as B O DM AS, with whatever order you prefer inside the various groups); as said by the relevant Wikipedia page:

这样写的时候,尤其是当用户不知道的乘法和除法都是平等的precedence的,因为是加法和减法这些助记符可能会产生误导。

These mnemonics may be misleading when written this way, especially if the user is not aware that multiplication and division are of equal precedence, as are addition and subtraction.

在换句话说,你所缺少的是正常(包括时做数学手动,并在任何理智的编程语言)的运营商实际上是由precedence的的的,其中分组乘除具有相同precedence(以及总和和减法)。所以,你的BODMAS规则,实际上居然是:

In other words, what you are missing is that normally (both when doing math "manually" and in any sane programming language) the operators are actually grouped by classes of precedence, where multiplication and division have the same precedence (as well as sum and subtraction). So, your "BODMAS rule" actually is actually:

() 
**
* /
+ - 

(我用 ** 作为幂运算符 - 因为它是在Python - ,因为Java并不提供;同时,()这里是分组符号,不经营者)

(I use ** as the exponentiation operator - as it is in Python -, as Java does not provide one; also, () here are grouping symbols, not operators)

运营商在同一行上的precedence由它们在离pression和它们的结合顺序确定(其中,对于算术运算符,是从左到右,尽管对于幂没有很好定义)。

The precedence of operators on the same line is determined by their order in an expression and their associativity (which, for arithmetic operators, is left to right, although for exponentiation is not well defined).

虽然在实数运算,这不是,除非谈到师(加法和减法是关联的,如果你认为减法除了对面的),在编程它真正相关的的双重要由于对FP数的数学和整数往往不关联。

Although for math on reals this is not really relevant unless talking about division (addition and subtraction are associative, if you consider subtraction as "addition of the opposite"), in programming it is double important, since math on FP numbers and on integers is often not associative.

此外,编程语言提供了更多的运营商,而不是联想/交换的,具有不同的相关性并没有那么完善的precedence规则,所以这是正常的,他们指定一个更精致的方式及其对运营商precedence规则

Also, programming languages provide many more operators, not associative/commutative, with different associativity and not so well established precedence rules, so it's normal that they specify their rules for operators precedence in a more refined way.

例如,见运营商precedence和关联表Java的的:它的方法比简单的BODMAS规则,这是不足以正确的前preSS问题更加复杂(因为有很多班,每班更多的运营商,类具有不同的相关性,.. )。

See for example the operator precedence and associativity table of Java: it's way more complicated than the simple "BODMAS rule", which is inadequate to correctly express it (since there are many classes, more operators in each class, classes with different associativity, ...).

这篇关于需要澄清BODMAS规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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