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

Function InterfaceToInt16Downcast

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

Source from the content-addressed store, hash-verified

115}
116
117func InterfaceToInt16Downcast(in interface{}) (int16, bool) {
118 var ok bool
119 if in, ok = JSONNumberToIntOrFloat(in); !ok {
120 return 0, false
121 }
122
123 switch casted := in.(type) {
124 case int8:
125 return int16(casted), true
126 case int16:
127 return casted, true
128 case int32:
129 if val := int16(casted); int32(val) == casted {
130 return val, true
131 }
132 case int:
133 if val := int16(casted); int(val) == casted {
134 return val, true
135 }
136 case int64:
137 if val := int16(casted); int64(val) == casted {
138 return val, true
139 }
140 case float32:
141 if val := int16(casted); float32(val) == casted {
142 return val, true
143 }
144 case float64:
145 if val := int16(casted); float64(val) == casted {
146 return val, true
147 }
148 }
149 return 0, false
150}
151
152func InterfaceToInt32(in interface{}) (int32, bool) {
153 var ok bool

Callers

nothing calls this directly

Calls 1

JSONNumberToIntOrFloatFunction · 0.85

Tested by

no test coverage detected