Casting between number types in golang

cobie picture cobie · Dec 13, 2012 · Viewed 32.1k times · Source

Could someone please tell me if go supports automatic casting of numeric types. Right now I have to manually convert the results of all my computation to int or int64 and keep track of what numeric type I am using.

Answer

dskinner picture dskinner · Dec 13, 2012

Go won't convert numeric types automatically for you.

From the language specification:

Conversions are required when different numeric types are mixed in an expression or assignment. For instance, int32 and int are not the same type even though they may have the same size on a particular architecture.