github.com/tobgu/qframe@v0.4.0/function/int.go (about) 1 package function 2 3 import "strconv" 4 5 // AbsI returns the absolute value of x. 6 func AbsI(x int) int { 7 if x < 0 { 8 return -x 9 } 10 return x 11 } 12 13 // PlusI returns x + y. 14 func PlusI(x, y int) int { 15 return x + y 16 } 17 18 // MinusI returns x - y. 19 func MinusI(x, y int) int { 20 return x - y 21 } 22 23 // MulI returns x * y. 24 func MulI(x, y int) int { 25 return x * y 26 } 27 28 // DivI returns x / y. y == 0 will cause panic. 29 func DivI(x, y int) int { 30 return x / y 31 } 32 33 // StrI returns the string representation of x. 34 func StrI(x int) *string { 35 result := strconv.Itoa(x) 36 return &result 37 } 38 39 // FloatI casts x to float. 40 func FloatI(x int) float64 { 41 return float64(x) 42 } 43 44 // BoolI returns bool representation of x. x == 0 => false, all other values result in true. 45 func BoolI(x int) bool { 46 return x != 0 47 }