Hello. Understanding the language, the question of calculating the number root arose. I'm too lazy to write my function and thought there are standard ones. such as calculating the degree of it

Pow(Double, Double) 

And calculating the square root

 sqrt(Double) 

I tried to score in pow fractional degree corresponding to the desired root 1 / x. But the calculation is not accurate, moreover, the inaccuracy increases with the degree of the root. Example:

 pow(1000.0, 1.0/3.0) 

It should turn out 10 , and I receive 9.999999999999998

Maybe there is a standard, but I can not find. You can tell if this built-in function is available.

Functions I test on Swift’s online site.

  • How do you display the result? - VAndrJ
  • This is real arithmetic and the result is quite accurate - 6 * 10e-14%. very good accuracy! - KoVadim
  • @KoVadim, the result is good, but no matter how much I encounter such tasks - if there should be a result of 10.0 (or another whole result), it is always 10.0 and received. - VAndrJ
  • one
    Many print functions sometimes cheat and give the result in a more expected form. To understand that the result you received is absolutely correct, you will get a cubic root from 10. - KoVadim
  • @KoVadim, therefore, asked why the author of the question displays the result. PS out of 10 received 2.15443469003188. - VAndrJ

1 answer 1

The best option is to install Xcode and test in your native environment. If there is no Mac for this purpose, you can install a virtual machine and work / learn in it. Moreover, nowadays these virtuals are getting updates along with real computers from Apple. And even a 6-year-old laptop with enough head performance is enough for decent work.

For very familiarizing purposes, yes, the online site will do, but if any problem comes out, first of all you need to check if this is the problem itself? (although Xcode also has complaints)

  • I have a mac. Thank you for the detailed schedule of your words that you gave in the comments earlier. - JoMax