github.com/bobyang007/helper@v1.1.3/reflecth/op-binary-gen.go (about) 1 //replacer:generated-file 2 3 package reflecth 4 5 import ( 6 "github.com/bobyang007/helper/strconvh" 7 "go/token" 8 ) 9 10 func binaryOpInt(x int, op token.Token, y int) (r int, err error) { 11 switch op { 12 case token.ADD: 13 return x + y, nil 14 case token.SUB: 15 return x - y, nil 16 case token.MUL: 17 return x * y, nil 18 case token.QUO: 19 return x / y, nil 20 case token.REM: 21 return x % y, nil 22 case token.AND: 23 return x & y, nil 24 case token.OR: 25 return x | y, nil 26 case token.XOR: 27 return x ^ y, nil 28 case token.AND_NOT: 29 return x &^ y, nil 30 default: 31 return 0, binaryOpInvalidOperatorSError(strconvh.FormatInt(x), op.String(), strconvh.FormatInt(y)) 32 } 33 } 34 35 func binaryOpInt8(x int8, op token.Token, y int8) (r int8, err error) { 36 switch op { 37 case token.ADD: 38 return x + y, nil 39 case token.SUB: 40 return x - y, nil 41 case token.MUL: 42 return x * y, nil 43 case token.QUO: 44 return x / y, nil 45 case token.REM: 46 return x % y, nil 47 case token.AND: 48 return x & y, nil 49 case token.OR: 50 return x | y, nil 51 case token.XOR: 52 return x ^ y, nil 53 case token.AND_NOT: 54 return x &^ y, nil 55 default: 56 return 0, binaryOpInvalidOperatorSError(strconvh.FormatInt8(x), op.String(), strconvh.FormatInt8(y)) 57 } 58 } 59 60 func binaryOpInt16(x int16, op token.Token, y int16) (r int16, err error) { 61 switch op { 62 case token.ADD: 63 return x + y, nil 64 case token.SUB: 65 return x - y, nil 66 case token.MUL: 67 return x * y, nil 68 case token.QUO: 69 return x / y, nil 70 case token.REM: 71 return x % y, nil 72 case token.AND: 73 return x & y, nil 74 case token.OR: 75 return x | y, nil 76 case token.XOR: 77 return x ^ y, nil 78 case token.AND_NOT: 79 return x &^ y, nil 80 default: 81 return 0, binaryOpInvalidOperatorSError(strconvh.FormatInt16(x), op.String(), strconvh.FormatInt16(y)) 82 } 83 } 84 85 func binaryOpInt32(x int32, op token.Token, y int32) (r int32, err error) { 86 switch op { 87 case token.ADD: 88 return x + y, nil 89 case token.SUB: 90 return x - y, nil 91 case token.MUL: 92 return x * y, nil 93 case token.QUO: 94 return x / y, nil 95 case token.REM: 96 return x % y, nil 97 case token.AND: 98 return x & y, nil 99 case token.OR: 100 return x | y, nil 101 case token.XOR: 102 return x ^ y, nil 103 case token.AND_NOT: 104 return x &^ y, nil 105 default: 106 return 0, binaryOpInvalidOperatorSError(strconvh.FormatInt32(x), op.String(), strconvh.FormatInt32(y)) 107 } 108 } 109 110 func binaryOpUint(x uint, op token.Token, y uint) (r uint, err error) { 111 switch op { 112 case token.ADD: 113 return x + y, nil 114 case token.SUB: 115 return x - y, nil 116 case token.MUL: 117 return x * y, nil 118 case token.QUO: 119 return x / y, nil 120 case token.REM: 121 return x % y, nil 122 case token.AND: 123 return x & y, nil 124 case token.OR: 125 return x | y, nil 126 case token.XOR: 127 return x ^ y, nil 128 case token.AND_NOT: 129 return x &^ y, nil 130 default: 131 return 0, binaryOpInvalidOperatorSError(strconvh.FormatUint(x), op.String(), strconvh.FormatUint(y)) 132 } 133 } 134 135 func binaryOpUint8(x uint8, op token.Token, y uint8) (r uint8, err error) { 136 switch op { 137 case token.ADD: 138 return x + y, nil 139 case token.SUB: 140 return x - y, nil 141 case token.MUL: 142 return x * y, nil 143 case token.QUO: 144 return x / y, nil 145 case token.REM: 146 return x % y, nil 147 case token.AND: 148 return x & y, nil 149 case token.OR: 150 return x | y, nil 151 case token.XOR: 152 return x ^ y, nil 153 case token.AND_NOT: 154 return x &^ y, nil 155 default: 156 return 0, binaryOpInvalidOperatorSError(strconvh.FormatUint8(x), op.String(), strconvh.FormatUint8(y)) 157 } 158 } 159 160 func binaryOpUint16(x uint16, op token.Token, y uint16) (r uint16, err error) { 161 switch op { 162 case token.ADD: 163 return x + y, nil 164 case token.SUB: 165 return x - y, nil 166 case token.MUL: 167 return x * y, nil 168 case token.QUO: 169 return x / y, nil 170 case token.REM: 171 return x % y, nil 172 case token.AND: 173 return x & y, nil 174 case token.OR: 175 return x | y, nil 176 case token.XOR: 177 return x ^ y, nil 178 case token.AND_NOT: 179 return x &^ y, nil 180 default: 181 return 0, binaryOpInvalidOperatorSError(strconvh.FormatUint16(x), op.String(), strconvh.FormatUint16(y)) 182 } 183 } 184 185 func binaryOpUint32(x uint32, op token.Token, y uint32) (r uint32, err error) { 186 switch op { 187 case token.ADD: 188 return x + y, nil 189 case token.SUB: 190 return x - y, nil 191 case token.MUL: 192 return x * y, nil 193 case token.QUO: 194 return x / y, nil 195 case token.REM: 196 return x % y, nil 197 case token.AND: 198 return x & y, nil 199 case token.OR: 200 return x | y, nil 201 case token.XOR: 202 return x ^ y, nil 203 case token.AND_NOT: 204 return x &^ y, nil 205 default: 206 return 0, binaryOpInvalidOperatorSError(strconvh.FormatUint32(x), op.String(), strconvh.FormatUint32(y)) 207 } 208 } 209 210 func binaryOpUint64(x uint64, op token.Token, y uint64) (r uint64, err error) { 211 switch op { 212 case token.ADD: 213 return x + y, nil 214 case token.SUB: 215 return x - y, nil 216 case token.MUL: 217 return x * y, nil 218 case token.QUO: 219 return x / y, nil 220 case token.REM: 221 return x % y, nil 222 case token.AND: 223 return x & y, nil 224 case token.OR: 225 return x | y, nil 226 case token.XOR: 227 return x ^ y, nil 228 case token.AND_NOT: 229 return x &^ y, nil 230 default: 231 return 0, binaryOpInvalidOperatorSError(strconvh.FormatUint64(x), op.String(), strconvh.FormatUint64(y)) 232 } 233 } 234 235 func binaryOpFloat64(x float64, op token.Token, y float64) (r float64, err error) { 236 switch op { 237 case token.ADD: 238 return x + y, nil 239 case token.SUB: 240 return x - y, nil 241 case token.MUL: 242 return x * y, nil 243 case token.QUO: 244 return x / y, nil 245 default: 246 return 0, binaryOpInvalidOperatorSError(strconvh.FormatFloat64(x), op.String(), strconvh.FormatFloat64(y)) 247 } 248 } 249 250 func binaryOpComplex64(x complex64, op token.Token, y complex64) (r complex64, err error) { 251 switch op { 252 case token.ADD: 253 return x + y, nil 254 case token.SUB: 255 return x - y, nil 256 case token.MUL: 257 return x * y, nil 258 case token.QUO: 259 return x / y, nil 260 default: 261 return 0, binaryOpInvalidOperatorSError(strconvh.FormatComplex64(x), op.String(), strconvh.FormatComplex64(y)) 262 } 263 } 264 265 func binaryOpComplex128(x complex128, op token.Token, y complex128) (r complex128, err error) { 266 switch op { 267 case token.ADD: 268 return x + y, nil 269 case token.SUB: 270 return x - y, nil 271 case token.MUL: 272 return x * y, nil 273 case token.QUO: 274 return x / y, nil 275 default: 276 return 0, binaryOpInvalidOperatorSError(strconvh.FormatComplex128(x), op.String(), strconvh.FormatComplex128(y)) 277 } 278 }