How do I calculate power-of in C#?

后端 未结 8 1565
别跟我提以往
别跟我提以往 2021-01-01 08:08

I\'m not that great with maths and C# doesn\'t seem to provide a power-of function so I was wondering if anyone knows how I would run a calculation like this:



        
8条回答
  •  悲&欢浪女
    2021-01-01 09:02

    Do not use Math.Pow

    When i use

    for (int i = 0; i < 10e7; i++)
    {
        var x3 = x * x * x;
        var y3 = y * y * y;
    }
    

    It only takes 230 ms whereas the following takes incredible 7050 ms:

    for (int i = 0; i < 10e7; i++)
    {
        var x3 = Math.Pow(x, 3);
        var y3 = Math.Pow(x, 3);
    }
    

提交回复
热议问题