如何错我用Math.Pow(A,B)函数这个C#代码? [英] How wrong do I use Math.Pow(a,b) function in this C# code?

查看:415
本文介绍了如何错我用Math.Pow(A,B)函数这个C#代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到什么毛病下面的代码,那里的MSVC#编译器店NAN在C:

I can not find anything wrong with the following code, whence the MSVC# compiler stores NAN in "c":

double c = Math.Pow(-8d, 1d / 3d);



虽然我觉得这条线应该算-2C,编译器店NAN在C ?
我错了任何事?

While I think this line should calculate -2 for "c", the compiler stores NAN in "c"? Am i wrong about anything?

推荐答案

浮点数的幂函数正基地或整体只被定义指数。尝试

The power function for floating point numbers is only defined for positive base or integral exponent. Try

double c = - Math.Pow(8d, 1d / 3d);



实际上,1/3不能精确表示为浮点数,但需要圆润。为圆形指数的准确真实的结果来根本不存在的理论。

Actually, 1/3 can't be represented exactly as a floating point number, but needs to be rounded. An exact real result for the rounded exponent does not even exist in theory.

这篇关于如何错我用Math.Pow(A,B)函数这个C#代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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