/usr/share/gocode/src/github.com/cznic/ql/coerce.go is in golang-github-cznic-ql-dev 1.0.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | // Copyright 2013 The ql Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// CAUTION: This file was generated automatically by
//
// $ go run helper/helper.go -o coerce.go
//
// DO NOT EDIT!
package ql
import (
"math"
"math/big"
"reflect"
"time"
)
func coerce(a, b interface{}) (x, y interface{}) {
if reflect.TypeOf(a) == reflect.TypeOf(b) {
return a, b
}
switch a.(type) {
case idealComplex, idealFloat, idealInt, idealRune, idealUint:
switch b.(type) {
case idealComplex, idealFloat, idealInt, idealRune, idealUint:
x, y = coerce1(a, b), b
if reflect.TypeOf(x) == reflect.TypeOf(y) {
return
}
return a, coerce1(b, a)
default:
return coerce1(a, b), b
}
default:
switch b.(type) {
case idealComplex, idealFloat, idealInt, idealRune, idealUint:
return a, coerce1(b, a)
default:
return a, b
}
}
}
func coerce1(inVal, otherVal interface{}) (coercedInVal interface{}) {
coercedInVal = inVal
if otherVal == nil {
return
}
switch x := inVal.(type) {
case nil:
return
case idealComplex:
switch otherVal.(type) {
//case idealComplex:
//case idealFloat:
//case idealInt:
//case idealRune:
//case idealUint:
//case bool:
case complex64:
return complex64(x)
case complex128:
return complex128(x)
//case float32:
//case float64:
//case int8:
//case int16:
//case int32:
//case int64:
//case string:
//case uint8:
//case uint16:
//case uint32:
//case uint64:
//case *big.Int:
//case *big.Rat:
//case time.Time:
//case time.Duration:
}
case idealFloat:
switch otherVal.(type) {
case idealComplex:
return idealComplex(complex(float64(x), 0))
case idealFloat:
return idealFloat(float64(x))
//case idealInt:
//case idealRune:
//case idealUint:
//case bool:
case complex64:
return complex64(complex(float32(x), 0))
case complex128:
return complex128(complex(float64(x), 0))
case float32:
return float32(float64(x))
case float64:
return float64(float64(x))
//case int8:
//case int16:
//case int32:
//case int64:
//case string:
//case uint8:
//case uint16:
//case uint32:
//case uint64:
//case *big.Int:
case *big.Rat:
return big.NewRat(1, 1).SetFloat64(float64(x))
//case time.Time:
//case time.Duration:
}
case idealInt:
switch otherVal.(type) {
case idealComplex:
return idealComplex(complex(float64(x), 0))
case idealFloat:
return idealFloat(int64(x))
case idealInt:
return idealInt(int64(x))
//case idealRune:
case idealUint:
if x >= 0 {
return idealUint(int64(x))
}
//case bool:
case complex64:
return complex64(complex(float32(x), 0))
case complex128:
return complex128(complex(float64(x), 0))
case float32:
return float32(int64(x))
case float64:
return float64(int64(x))
case int8:
if x >= math.MinInt8 && x <= math.MaxInt8 {
return int8(int64(x))
}
case int16:
if x >= math.MinInt16 && x <= math.MaxInt16 {
return int16(int64(x))
}
case int32:
if x >= math.MinInt32 && x <= math.MaxInt32 {
return int32(int64(x))
}
case int64:
return int64(int64(x))
//case string:
case uint8:
if x >= 0 && x <= math.MaxUint8 {
return uint8(int64(x))
}
case uint16:
if x >= 0 && x <= math.MaxUint16 {
return uint16(int64(x))
}
case uint32:
if x >= 0 && x <= math.MaxUint32 {
return uint32(int64(x))
}
case uint64:
if x >= 0 {
return uint64(int64(x))
}
case *big.Int:
return big.NewInt(int64(x))
case *big.Rat:
return big.NewRat(1, 1).SetInt64(int64(x))
//case time.Time:
case time.Duration:
return time.Duration(int64(x))
}
case idealRune:
switch otherVal.(type) {
case idealComplex:
return idealComplex(complex(float64(x), 0))
case idealFloat:
return idealFloat(int64(x))
case idealInt:
return idealInt(int64(x))
case idealRune:
return idealRune(int64(x))
case idealUint:
return idealUint(int64(x))
//case bool:
case complex64:
return complex64(complex(float32(x), 0))
case complex128:
return complex128(complex(float64(x), 0))
case float32:
return float32(int64(x))
case float64:
return float64(int64(x))
case int8:
return int8(int64(x))
case int16:
return int16(int64(x))
case int32:
return int32(int64(x))
case int64:
return int64(int64(x))
//case string:
case uint8:
return uint8(int64(x))
case uint16:
return uint16(int64(x))
case uint32:
return uint32(int64(x))
case uint64:
return uint64(int64(x))
case *big.Int:
return big.NewInt(int64(x))
case *big.Rat:
return big.NewRat(1, 1).SetInt64(int64(x))
//case time.Time:
case time.Duration:
return time.Duration(int64(x))
}
case idealUint:
switch otherVal.(type) {
case idealComplex:
return idealComplex(complex(float64(x), 0))
case idealFloat:
return idealFloat(uint64(x))
case idealInt:
if x <= math.MaxInt64 {
return idealInt(int64(x))
}
//case idealRune:
case idealUint:
return idealUint(uint64(x))
//case bool:
case complex64:
return complex64(complex(float32(x), 0))
case complex128:
return complex128(complex(float64(x), 0))
case float32:
return float32(uint64(x))
case float64:
return float64(uint64(x))
case int8:
if x <= math.MaxInt8 {
return int8(int64(x))
}
case int16:
if x <= math.MaxInt16 {
return int16(int64(x))
}
case int32:
if x <= math.MaxInt32 {
return int32(int64(x))
}
case int64:
if x <= math.MaxInt64 {
return int64(int64(x))
}
//case string:
case uint8:
if x >= 0 && x <= math.MaxUint8 {
return uint8(int64(x))
}
case uint16:
if x >= 0 && x <= math.MaxUint16 {
return uint16(int64(x))
}
case uint32:
if x >= 0 && x <= math.MaxUint32 {
return uint32(int64(x))
}
case uint64:
return uint64(uint64(x))
case *big.Int:
return big.NewInt(0).SetUint64(uint64(x))
case *big.Rat:
return big.NewRat(1, 1).SetInt(big.NewInt(0).SetUint64(uint64(x)))
//case time.Time:
case time.Duration:
if x <= math.MaxInt64 {
return time.Duration(int64(x))
}
}
}
return
}
|