MCPcopy Index your code
hub / github.com/cortexlabs/cortex / InterfaceToFloat32

Function InterfaceToFloat32

pkg/lib/cast/interface.go:315–338  ·  view source on GitHub ↗

InterfaceToFloat32 will convert any int or float type

(in interface{})

Source from the content-addressed store, hash-verified

313
314// InterfaceToFloat32 will convert any int or float type
315func InterfaceToFloat32(in interface{}) (float32, bool) {
316 var ok bool
317 if in, ok = JSONNumberToIntOrFloat(in); !ok {
318 return 0, false
319 }
320
321 switch casted := in.(type) {
322 case int8:
323 return float32(casted), true
324 case int16:
325 return float32(casted), true
326 case int32:
327 return float32(casted), true
328 case int:
329 return float32(casted), true
330 case int64:
331 return float32(casted), true
332 case float32:
333 return casted, true
334 case float64:
335 return float32(casted), true
336 }
337 return 0, false
338}
339
340// InterfaceToFloat64 will convert any int or float type
341func InterfaceToFloat64(in interface{}) (float64, bool) {

Callers 4

Float32PtrFunction · 0.92
Float32Function · 0.92
Float32ListFunction · 0.92
InterfaceToFloat32SliceFunction · 0.85

Calls 1

JSONNumberToIntOrFloatFunction · 0.85

Tested by

no test coverage detected