Is ** Operator valid?

I am trying to use ** operator to calculate the 2 power 32. But I keep getting an error saying
invalid indirect of 32 (type untyped number)
It is considering the second * to mean pointer to 32.

Isn’t 2**32 a valid expression?
I see that it is used in the comment of this documentation https://golang.org/pkg/math/
However I don’t see this being used elsewhere.

2 Likes

No, golang has no power operator by itself. The math package though provides a function for floats. For Integers you need to implement them on your own, but be aware of the fact that you’ll be out of bounds pretty quickly…

4 Likes

Go does not power operator (** or ^ or whatever).
Yes, you can use ,math package and Pow to make the math.

2 Likes

Any reason why Go did not add this as an operator, this is a basic operator. I am only curious!

2 Likes

jeje, No clue too!!. It could be a Go’s parents decision…

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.