Math.Pow未正确计算 [英] Math.Pow is not calculating correctly
问题描述
我在与C#中的问题。要precise与Math.pow()。如果我尝试计算15 ^ 14,然后我得到29192926025390624。但是,如果我与Wolfram Alpha的计算它我得到29192926025390625。正如你所看到的这个唯一的区别是1号。 Wolfram Alpha的是正确的,但。为什么不是C#?和我怎么解决这个问题,所以我可以在C#中的正确值?7
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 get "29192926025390625". As you can see this only difference is 1 number. Wolfram Alpha is correct though. Why isn't C# ? and how do I fix this so I can get the correct value in C# ?7
我的code是相当简单的,因为我只是硬codeD的例子尝试。所以,我在做什么是: Math.Pow(15,14);
这使得 29192926025390624
。而不是29192926025390625,这是正确的答案。
My code is fairly simple since I'm just trying with hardcoded examples. So what I'm doing is : Math.Pow(15,14);
This gives 29192926025390624
. And not "29192926025390625" which is the correct answer.
链接: Wolfram Alpha的
推荐答案
Math.Pow
定义浮点类型,它的工作不准确的。如果您需要任意precision整数,使用任意precision整数类型如的 BigInteger的结构。 BigInteger的也有战俘方法。
Math.Pow
operates on floating-point types, which are by definition inaccurate. If you need arbitrary precision integers, use an arbitrary precision integer type such as the BigInteger structure. BigInteger also has a Pow method.
这篇关于Math.Pow未正确计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!