dpt62283 2018-01-06 01:45
浏览 77

为什么golang移位运算符优先于加法? [关闭]

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

It seems only golang >> is taking precedence over +? But why?

  • 写回答

1条回答 默认 最新

  • dongshao4207 2018-01-06 01:50
    关注

    This is a difference in language philosophy and usability. Go views the operations as multiplication/division by powers of 2, a functional view. The other languages regard it as a bit-based operators, which they class next to Boolean operators. This is based more on a sense of common data type/view.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法