小编Piy*_*gal的帖子

Why go does not have function to calculate absolute value for integer datatype?

In go, why there is no function which directly calculates absolute value for integer datatypes. Currently all integer values has to be type casted to float64 and then it has to be used as a parameter in math.Abs() function. And it returns float64 datatype only, which again has to be type casted into integer datatype.

Like this code is giving error as Go is statically typed language, so does not allows different datatype.

./prog.go:12:39: cannot use x (type int64) as …

casting go absolute-value

-1
推荐指数
2
解决办法
205
查看次数

标签 统计

absolute-value ×1

casting ×1

go ×1