MCPcopy Create free account
hub / github.com/cortexlabs/cortex / InterfaceToInt64Downcast

Function InterfaceToInt64Downcast

pkg/lib/cast/interface.go:285–312  ·  view source on GitHub ↗
(in interface{})

Source from the content-addressed store, hash-verified

283}
284
285func InterfaceToInt64Downcast(in interface{}) (int64, bool) {
286 var ok bool
287 if in, ok = JSONNumberToIntOrFloat(in); !ok {
288 return 0, false
289 }
290
291 switch casted := in.(type) {
292 case int8:
293 return int64(casted), true
294 case int16:
295 return int64(casted), true
296 case int32:
297 return int64(casted), true
298 case int:
299 return int64(casted), true
300 case int64:
301 return casted, true
302 case float32:
303 if val := int64(casted); float32(val) == casted {
304 return val, true
305 }
306 case float64:
307 if val := int64(casted); float64(val) == casted {
308 return val, true
309 }
310 }
311 return 0, false
312}
313
314// InterfaceToFloat32 will convert any int or float type
315func InterfaceToFloat32(in interface{}) (float32, bool) {

Callers

nothing calls this directly

Calls 1

JSONNumberToIntOrFloatFunction · 0.85

Tested by

no test coverage detected