1 Star 0 Fork 1

landy / qlang

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
boolean.go 2.19 KB
Copy Edit Raw Blame History
xushiwei authored 2016-05-02 02:34 . #54 type(['a', 'b']) gets []int
package builtin
// -----------------------------------------------------------------------------
// Not returns !a
//
func Not(a interface{}) interface{} {
if a1, ok := a.(bool); ok {
return !a1
}
return panicUnsupportedOp1("!", a)
}
// LT returns a < b
//
func LT(a, b interface{}) interface{} {
switch a1 := a.(type) {
case int:
switch b1 := b.(type) {
case int:
return a1 < b1
case float64:
return float64(a1) < b1
}
case float64:
switch b1 := b.(type) {
case int:
return a1 < float64(b1)
case float64:
return a1 < b1
}
case string:
if b1, ok := b.(string); ok {
return a1 < b1
}
}
return panicUnsupportedOp2("<", a, b)
}
// GT returns a > b
//
func GT(a, b interface{}) interface{} {
switch a1 := a.(type) {
case int:
switch b1 := b.(type) {
case int:
return a1 > b1
case float64:
return float64(a1) > b1
}
case float64:
switch b1 := b.(type) {
case int:
return a1 > float64(b1)
case float64:
return a1 > b1
}
case string:
if b1, ok := b.(string); ok {
return a1 > b1
}
}
return panicUnsupportedOp2(">", a, b)
}
// LE returns a <= b
//
func LE(a, b interface{}) interface{} {
switch a1 := a.(type) {
case int:
switch b1 := b.(type) {
case int:
return a1 <= b1
case float64:
return float64(a1) <= b1
}
case float64:
switch b1 := b.(type) {
case int:
return a1 <= float64(b1)
case float64:
return a1 <= b1
}
case string:
if b1, ok := b.(string); ok {
return a1 <= b1
}
}
return panicUnsupportedOp2("<=", a, b)
}
// GE returns a >= b
//
func GE(a, b interface{}) interface{} {
switch a1 := a.(type) {
case int:
switch b1 := b.(type) {
case int:
return a1 >= b1
case float64:
return float64(a1) >= b1
}
case float64:
switch b1 := b.(type) {
case int:
return a1 >= float64(b1)
case float64:
return a1 >= b1
}
case string:
if b1, ok := b.(string); ok {
return a1 >= b1
}
}
return panicUnsupportedOp2(">=", a, b)
}
// EQ returns a == b
//
func EQ(a, b interface{}) interface{} {
return a == b
}
// NE returns a != b
//
func NE(a, b interface{}) interface{} {
return a != b
}
// -----------------------------------------------------------------------------
Go
1
https://gitee.com/landylee007/qlang.git
git@gitee.com:landylee007/qlang.git
landylee007
qlang
qlang
v2.9.60

Search

53164aa7 5694891 3bd8fe86 5694891