C#Math.Pow()被打破 [英] C# Math.Pow() is broken

查看:692
本文介绍了C#Math.Pow()被打破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不,这不会(我的理解)涉及整数除法或浮点舍入的问题。

And no, this does not (to my understanding) involve integer division or floating-point rounding issues.

我的确切code是:

    static void Main(string[] args)
    {
        double power = (double)1.0 / (double)7.0;
        double expBase = -128.0;
        System.Console.WriteLine("sanity check: expected: -128 ^ 0.142857142857143 = -2.    actual: " + expBase + " ^ " + power + " = " + Math.Pow(expBase, power));
        System.Console.ReadLine();
    }

的输出是:

完整性检查:预期:-128 ^ 0.142857142857143 = -2。实际:-128 ^ 0.14285 7142857143 = NaN的

sanity check: expected: -128 ^ 0.142857142857143 = -2. actual: -128 ^ 0.14285 7142857143 = NaN

目标框架此code为(根据溶液性质).NET Framework 4.0客户端配置文件。

The Target Framework for this code is (according to solution properties) .NET Framework 4.0 Client Profile.

奇怪的是我没有找到任何提及此畅游网络世界中。我是不是疯了服用药丸来了!?

Strangely I haven't found any mention of this anywhere on the Web. Am I taking crazy pills here!?

推荐答案

好像是完全按照规定的;从的Math.Pow()备注部分战俘(X,Y);

Seems to be exactly as specified; from the Math.Pow() remarks section on Pow(x,y);

参数
  X - LT; 0但不NegativeInfinity; y不是整数,NegativeInfinity,或PositiveInfinity时

Parameters
x < 0 but not NegativeInfinity; y is not an integer, NegativeInfinity, or PositiveInfinity.

结果 -   为NaN

Result
NaN

这篇关于C#Math.Pow()被打破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆