I had got task to do:
Make func that accepts interface and returns *float64. Func should convert any type, that can be converted without reduction.
So i did this one:
func getValuePtr(val interface{}) (value *float64) {
switch v := val.(type) {
case int:
vv := float64(v)
value = &vv
case uint32:
vv := float64(v)
value = &vv
case int32:
vv := float64(v)
value = &vv
case uint64:
vv := float64(v)
value = &vv
case int64:
vv := float64(v)
value = &vv
case float32:
vv := float64(v)
value = &vv
case float64:
vv := float64(v)
value = &vv
}
return
}
It seems too complex for me. Maybe it isnt 🙂 Maybe you know better solution?
New contributor
user25265096 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.