C# – Nth root of small number return an unexpected result in C#


When I try to take the N th root of a small number using C# I get a wrong number.

For example, when I try to take the third root of 1.07, I get 1, which is clearly not true.

Here is the exact code I am using to get the third root.


How do I solve this problem?

I would guess that this is a floating point arithmetic issue, but I don't know how to handle it.

Best Solution

C# is treating the 1 and the 3 as integers, you need to do the following:




It is actually interesting because the implicit widening conversion makes you make a mistake.

Related Question