Search code examples
c#.netalgebrapowcalculus

Math.Pow() vs Math.Exp() C# .Net


Can anyone provide an explanation of the difference between using Math.Pow() and Math.Exp() in C# and .net ?

Is Exp()just taking a number to the Power using itself as the Exponent?


Solution

  • Math.Pow computes x y for some x and y.

    Math.Exp computes e x for some x, where e is Euler's number.

    Note that while Math.Pow(Math.E, d) produces the same result as Math.Exp(d), a quick benchmark comparison shows that Math.Exp actually executes about twice as fast as Math.Pow:

    Trial Operations       Pow       Exp
        1       1000 0.0002037 0.0001344 (seconds)
        2     100000 0.0106623 0.0046347 
        3   10000000 1.0892492 0.4677785