I'm trying to learn Go and working on a rain intensity tool. For this tool I have to make a calculation like this:
var intensity float32
intensity = 10^((value−109)÷32)
The value is an uint8
, ranging from 0 to 255. The intensity variable is a float.
However, Go tells me that
cannot use 10 ^ (value - 109) / 32 (type uint8) as type float32 in assignment
How can I solve this?
÷
operator in Go and ^
is a bitwise XOR, you need to use Pow
functions from math
packagetype(expr)
, i.e. float32(1)
That said:
intensity = float32(math.Pow(10, float64((value - 109) / 32)))
// - OR -
intensity = float32(math.Pow10(int((value - 109) / 32)))