Currently, math.Pow()
and math.sqrt
take float64
type arguments.
Do we have equivalent functions that take int
type arguments?
Currently, math.Pow()
and math.sqrt
take float64
type arguments.
Do we have equivalent functions that take int
type arguments?
If your return value is a float, you can use Ceil or Floor from the math package and then convert it to an int.
n := 5.5
o := math.Floor(n)
p := int(math.Pow(o, 2))
fmt.Println("Float:", n)
fmt.Println("Floor:", o)
fmt.Println("Square:", p)
5.5
5
25
Keep in mind that Floor still returns a float64, so you will still want to wrap it in int()
just create a float64 object using the int value. Example if int = 10.
var x float64 = 10
var b = math.Pow(2, x)
What you can do is type-cast a float to your value.
int a=10,b=2;
math.Pow(float(a),float(b));