GO語言"go/constant"包中"BinaryOp"函數的用法及代碼示例。
用法:
func BinaryOp(x_ Value, op token.Token, y_ Value) Value
BinaryOp 返回二進製表達式 x op y 的結果。必須為操作數定義操作。如果其中一個操作數為未知,則結果為未知。 BinaryOp 不處理比較或移位;改用比較或移位。
要強製對Int 操作數進行整數除法,請使用 op == token.QUO_ASSIGN 而不是 token.QUO;在這種情況下,結果保證為Int。除以零會導致運行時Panics。
例子:
package main
import (
"fmt"
"go/constant"
"go/token"
)
func main() {
// 11 / 0.5
a := constant.MakeUint64(11)
b := constant.MakeFloat64(0.5)
c := constant.BinaryOp(a, token.QUO, b)
fmt.Println(c)
}
輸出:
22
相關用法
- GO Buffer.Bytes用法及代碼示例
- GO Buffer.Read用法及代碼示例
- GO B.RunParallel用法及代碼示例
- GO Buffer.Len用法及代碼示例
- GO Buffer用法及代碼示例
- GO Buffer.Next用法及代碼示例
- GO Buffer.ReadByte用法及代碼示例
- GO B.ReportMetric用法及代碼示例
- GO Base用法及代碼示例
- GO Buffer.Cap用法及代碼示例
- GO Builder用法及代碼示例
- GO ByteOrder用法及代碼示例
- GO Buffer.Grow用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO LeadingZeros32用法及代碼示例
- GO NewFromFiles用法及代碼示例
- GO Regexp.FindString用法及代碼示例
- GO Time.Sub用法及代碼示例
- GO Regexp.FindAllIndex用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 BinaryOp。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。