I’m writing a cube root function in Google Go using Newton’s method. I want to check the results using math/cmplx.Pow(), but for the life of me, I can’t figure out how. How do I do this?
I’m writing a cube root function in Google Go using Newton’s method. I want
Share
Have you tried
myCubicRootOfx = Pow(x, 1.0/3)?edited: thanks to
Jason McCrearycomment:We cannot use
1/3as the 2nd parameter toPowas this is a integer division and hence doesn’t produce the expected 1/3 value. By using1.0/3or1/3.0etc. we effectively produce a float with the 0.333333… value.