go - 为什么 golang 移位运算符优先于加法?

标签 go operator-precedence

<分区>

java:  System.out.println(1 + (9 - 1) >> 1);  // OUPUT: "4"
golang: fmt.Println(1 + (9 - 1) >> 1) // OUPUT: "5"

Go:https://kuree.gitbooks.io/the-go-programming-language-report/content/31/text.html

Java:https://introcs.cs.princeton.edu/java/11precedence/

python :http://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html

C/C++:http://en.cppreference.com/w/c/language/operator_precedence

似乎只有 golang >> 优先于 +?但是为什么?

最佳答案

这是语言哲学和可用性的不同。 Go 将运算视为 2 的幂的乘法/除法,一种函数式 View 。其他语言将其视为基于位的运算符,它们将其归类为 bool 运算符。这更多是基于对通用数据类型/ View 的感觉。

关于go - 为什么 golang 移位运算符优先于加法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48123519/

相关文章:

php - "&&"和 "and": Operator precedence and short circuiting 之间的区别

java - 如何使用 gorm 动态添加查询参数?

go - Go是否容易受到缓冲区溢出的影响

go - Go中的树引用父亲ID

c - "sizeof"的结果取决于括号的位置。为什么?

c# - C# 中的运算符优先级

c++ - 运算符与函数行为

arrays - golang 中的变量范围

operator-precedence - 为什么语言具有运算符优先级?

python - 这个表达式是如何计算的? "f"中的 "foo"== 真