[英]C# math.pow cube root calculation
如何计算(0.015*(0.05*0.05))
的立方根?
我尝试了以下解决方案:
double result = Math.Pow(0.015 * (0.05 * 0.05), 1.0/3.0);
我得到0.03347
。 来自Volframalpha的相同计算: 0.015*(0.05*0.05)^0.33
得到0.00207
。
我在这做错了什么?
我有三个问题。
您正在表达式的一部分中使用Math.Pow(),但是,您将希望在表达式的第一部分中使用Math.Sqrt(),该部分稍后在对话期间给出。
其次,表达式中的括号分组存在问题,导致对表达式的无效评估
第三,您需要在没有小数值的数值后使用'd'字符后缀来评估预期结果。
等式:(0.3d *((0.0015d *(0.793700526d + Math.Sqrt(0.7071068)))+(0.015d * Math.Pow((0.05d * 0.05d),(1d / 3d)))))
编码:
using System;
namespace POW
{
class Program
{
static void Main(string[] args)
{
// Corrected calculation derived from comment conversation given by author
double myCalculation1 = (0.3 * ((0.0015 * (0.793700526 + Math.Sqrt(0.7071068))) + (0.015 * Math.Pow((0.05 * 0.05), (1 / 3)))));
// d suffix used to ensure the non decimal value is treated as a decimal
double myCalculation2 = (0.3 * ((0.0015 * (0.793700526 + Math.Sqrt(0.7071068))) + (0.015 * Math.Pow((0.05 * 0.05), (1d/3d)))));
// Output the value of myPow
Console.WriteLine("The value of myCalculation is: {0}", myCalculation1);
Console.WriteLine("The value of myCalculation is: {0}", myCalculation2);
}
}
}
重要的是,按照惯例,您需要在每个数字后面使用'd'后缀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.