This is a compile error, so I don't think this matter I modify the code , add float , it is the same.
func LimRange(x, low, high interface{}) float64 { var fx, flow, fhigh float64 switch v := x.(type) { case int: //OK case int8: case int16: case int32: case float32: case float64: return float64(v) //OK default: return math.NaN() } switch v := x.(type) { case int,int8,int16,int32,float32,float64: return float64(v) //Error: cannot convert v (type interface {}) to type float64: need type assertion default: return math.NaN() } a :=1 switch a { case 1,2: //OK println("1,2") } return math.Max(math.Min(fx, fhigh), flow) } var Icolor int16 = 3 Icolor = int16(LimRange(Icolor, 0, 1)) println("Icolor=", Icolor) 在 2017年1月12日星期四 UTC+8上午9:21:29,kortschak写道: > > On Wed, 2017-01-11 at 17:15 -0800, hui zhang wrote: > > switch v := x.(type) { > > case int,int8,int16,int32: > > What type is v here? It can't be any of the four types you have listed > in the case since are not assignable to each other without conversion, > so it must be an interface{}. interface{} cannot be converted to > float64 without an assertion to a numerical type first. > > > return float64(v) > > default: > > > > -- 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.