Back to Devexpress

Convert to Math.Pow Call

coderushforroslyn-115648-refactoring-assistance-convert-to-math-pow-call.md

latest1.3 KB
Original Source

Convert to Math.Pow Call

  • Aug 03, 2020

Purpose

Replaces the multiplication of an expression by itself to the Math.Pow method call. Multiplication by the same expression is not a recommended way to raise it to a power, because the length of such a construction increases with the required power. Use the Math.Pow method instead.

Availability

Available when the cursor is on an expression in which a variable or expression is multiplied by itself.

Usage

  1. Place the caret on an expression in which a variable is multiplied by itself.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Convert to Math.Pow Call from the menu.

After execution, the Refactoring converts the multiplication by the same variable into the equivalent Math.Pow method call.

csharp
double Polynom2(double x, Tuple<double, double, double> k) => k.Item3 * (Math.Pow(x, 2)) + k.Item2 * x + k.Item1;

See Also

Use String.Compare

ForEach to Linq

Boolean to Enum

Convert to Tuple