Skip to main content

Convert to Math.Pow Call

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.

    Note

    The blinking cursor shows the caret’s position at which the Refactoring is available.

    double Polynom2(double x, Tuple<double, double, double> k) => k.Item3 * (x * x) + k.Item2 * x + k.Item1;
    
  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.

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