Math.Pow is not calculating correctly

后端 未结 6 1277
萌比男神i
萌比男神i 2020-12-01 18:52

I\'m having a problem with C#. To be precise with the Math.pow(). If I try to calculate 15^14 then I get \"29192926025390624\". But if I calculate it with Wolfram Alpha I ge

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 19:45

    Math.Pow works on doubles. This implementation with long gets the correct answer:

    Func power = null;
    power = (i, p) => p == 1 ? i : i*power(i, p - 1);
    Console.WriteLine(power(15, 14));
    

提交回复
热议问题