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

Function InterfaceToInt8Downcast

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

Source from the content-addressed store, hash-verified

51}
52
53func InterfaceToInt8Downcast(in interface{}) (int8, bool) {
54 var ok bool
55 if in, ok = JSONNumberToIntOrFloat(in); !ok {
56 return 0, false
57 }
58
59 switch casted := in.(type) {
60 case int8:
61 return casted, true
62 case int16:
63 if val := int8(casted); int16(val) == casted {
64 return val, true
65 }
66 case int32:
67 if val := int8(casted); int32(val) == casted {
68 return val, true
69 }
70 case int:
71 if val := int8(casted); int(val) == casted {
72 return val, true
73 }
74 case int64:
75 if val := int8(casted); int64(val) == casted {
76 return val, true
77 }
78 case float32:
79 if val := int8(casted); float32(val) == casted {
80 return val, true
81 }
82 case float64:
83 if val := int8(casted); float64(val) == casted {
84 return val, true
85 }
86 }
87 return 0, false
88}
89
90func InterfaceToInt16(in interface{}) (int16, bool) {
91 var ok bool

Callers 1

Calls 1

JSONNumberToIntOrFloatFunction · 0.85

Tested by 1