B
B
Badsignal2018-04-05 01:12:03
Swift
Badsignal, 2018-04-05 01:12:03

Why does the pow function calculate the cube root this way?

Hello!
Quite by accident, I recently encountered the fact that the function pow(125, 1.0/3.0) as a result gives the answer 4.999999999999999991, and not 5. At the same time, the built-in cbrt function gives the correct answer. I'm just worried about the rest of the roots.
Can anyone explain why this happens (although I guess that it is possible as a result of dividing 1 by 3), and most importantly, what to do with it in other powers (for example, 1/7)?
Thank you!
PS But from 27 the cube root is correct

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2018-04-05
@shurshur

The pow function calculates using other formulas that are universal for various exponents, but give more error.
I remember back in the Soviet calculators MK (I had MK-61) 2^2 when using the x^2 operation gave 4, and with x^y it turned out 3.9999996.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question