Go does not have a notion of casting, and working towards a solution that starts with a need for generics will end in tears.
If you want to have a universal numeric -> float64 conversion, this[1] might work, though I really don't think it is a good idea, and won't help in your broader scheme to make a Min(a, b T) T since you can't compile type specify the returned T generically. The best you can do is Min(a, b T) interface{}. In practice, it's better to implement a min(a, b T) T for each T that you actually need (it's only 5 lines for each type and you probably don't need every numerical type). [1]https://play.golang.org/p/K7TnHHAx5O On Thu, 2017-01-12 at 10:56 +0800, hui zhang wrote: > If I want to cast interface{} to float64 > interface{} could be int8 int16 int32 int64 float32..... > What is the proper way. > > consider a generic function for min > func Min(a T, b T) T { > } > What is the best way to implement it in go -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.