C#Math.Pow()返回无穷大 [英] C# Math.Pow () return infinity
问题描述
类数学函数的问题
double xx = 65 ;
double aa = 331 ;
double result = Math.Pow(xx,aa);
// 最终结果是......无限
然后我使用类BigInteger并返回实数但结果不一样是windows计算器
--- ----------------------------------------
windows计算器:
65 ^ 331 = 1.1866456424809823888425970808655e + 600
----------------- --------------------------
类数学返回无穷大和类BigIntger返回数字不一样windows计算器结果
为什么我使用数字65和331,因为我的编程算法必须是最终结果相同的windows计算器_
-------- --------------------------------------
double a = 65 ;
double y = 331 ;
double mode_;
double js = 17741 ;
double final_ = power_get(a,y);
double mode_ = final%js; // 结果必须是530?
private static double power_get( double power, double E)
{
double base_pow =权力;
double top_pow = E;
double exploit_js = base_pow; // 2
double i;
for (i = 0 ; i < ; top_pow - 1 ; i ++)
{
exploit_js * = base_pow;
}
return exploit_js;
}
i需要获得此计算的最终结果的方法是= 530;
i知道double是有限的存储但是什么?变量
类型可以解决这个问题并获得结果final = 530?
您观察到的是正确的有效结果。也许你所有的问题都是熟悉浮点数,作为实数这样的概念和数学抽象的近似计算机表示:
http://en.wikipedia.org/wiki/Floating-point_number [ ^ ],
http://en.wikipedia.org/wiki/Real_number [ ^ ]。
需要注意的是:作为微积分基础的实数理论是一个极其深刻和复杂的领域。数学。
-SA
你知道你的代码不会按原样编译吗? br />
考虑到可能很难/不可能完全匹配C#的内部算法和d Windows Calc使用的ata-structures ...除非MS发布它们。
您可以使用WinAPI平台调用工具使用'SetParent和'MoveWindow来实现-of嵌入你的.NET C#应用程序中的Win计算器,但我怀疑这将是不能令人满意的,并且与它的互操作...就像在阅读显示文本编辑窗口的内容......是...棘手。
MS有一个使用C#中的SendKeys控制Win计算器的例子:[ ^ ]。
.NET NameSpace System.Windows.Automation是一种尝试互操作的更好方法;请参阅:[ ^ ]。
problems with class math function pow when i do 65 ^ 331 return infinity
double xx=65;
double aa=331;
double result =Math.Pow(xx,aa);
//final result is ... infinity
then i used class BigInteger and return real number but the result is not same windows calculator
-------------------------------------------
windows calculator :
65 ^ 331 =1.1866456424809823888425970808655e+600
-------------------------------------------
class math return infinity and class BigIntger return number not same windows calculator result
why i use the number 65 and 331 because i programming algorithmic must be result final same windows calculator _
----------------------------------------------
double a=65;
double y=331;
double mode_;
double js=17741;
double final_ =power_get(a,y);
double mode_=final % js; //must be result is 530 ?
private static double power_get(double power, double E)
{
double base_pow = power;
double top_pow =E;
double exploit_js = base_pow;//2
double i;
for (i = 0; i < top_pow - 1; i++)
{
exploit_js *= base_pow;
}
return exploit_js;
}
i need way to get a final result for this calculate is= 530;
i know double is limited storage but what ? the variable
type can be solve this and get the result final is =530?
What you observe are the correct valid results. Perhaps all your problem is to get familiar with floating-point numbers, as an approximate computer representation of such concept and mathematical abstraction as real numbers:
http://en.wikipedia.org/wiki/Floating-point_number[^],
http://en.wikipedia.org/wiki/Real_number[^].
Just to note: the theory of real numbers, being a base of calculus, is an extremely deep and complex field of mathematics.
—SA
You are aware your code will not compile as is ?
Consider that it might be difficult/impossible to match exactly in C# the internal algorithms and data-structures used by Windows Calc ... unless MS published them.
You could, using the WinAPI Platform Invoke facilities use 'SetParent, and 'MoveWindow, to kind-of "embed" the Win Calculator in your .NET C# app, but I suspect that would be unsatisfactory, and inter-operation with it ... as in reading the contents of the display text-edit window ... is ... tricky.
MS has an example of using 'SendKeys in C# to control the Win Calculator: [^].
The .NET NameSpace System.Windows.Automation is a better way to attempt to inter-operate; see: [^].
这篇关于C#Math.Pow()返回无穷大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!