Решив одну ошибку, я пришел к интересным открытиям.
Результат этой процедуры
static void Main(string[] args)
{
int i4 = 4;
Console.WriteLine("int i4 = 4;");
Console.WriteLine("i4 % 1 = {0}", i4 % 1);
double d4 = 4.0;
Console.WriteLine("double d4 = 4.0;");
Console.WriteLine("d4 % 1 = {0}", d4 % 1);
Console.WriteLine("-----------------------------------------------------------");
int i64 = 64;
double dCubeRootOf64 = Math.Pow(i64, 1.0 / 3.0);
Console.WriteLine("int i64 = 64;");
Console.WriteLine("double dCubeRootOf64 = Math.Pow(i64, 1.0 / 3.0) = {0}", dCubeRootOf64);
Console.WriteLine("dCubeRootOf64 = {0}", dCubeRootOf64);
Console.WriteLine("dCubeRootOf64 % 1 = {0} ?????????????? Why 1. ??????????", dCubeRootOf64 % 1);
Console.ReadLine();
}
is
int i4 = 4;
i4 % 1 = 0
double d4 = 4.0;
d4 % 1 = 0
-----------------------------------------------------------
int i64 = 64;
double dCubeRootOf64 = Math.Pow(i64, 1.0 / 3.0) = 4
dCubeRootOf64 = 4
dCubeRootOf64 % 1 = 1 ?????????????? Why 1. ??????????
int 4 % 1 = 0
-- верно
double 4.0 % 1 = 0
-- верно
Но ошибка в:
Math.Pow(64, 1,0 / 3,0) % 1 = 1
Кубический корень из 64 равен 4. Почему в таком случае 4 % 1 = 1
?
Math.Pow(x, 1.0 / 3.0)
не вычисляет кубический корень, даже если Pow был бесконечно точным (а это не так), потому что1.0 / 3.0
не одна треть, а 0,333333333333333331. - person harold   schedule 24.05.2012