x to the power y in Delphi


How we get the power of a number in Delphi?


This can be done with the function Power(Base, Exponent).
Because this function is in Delphi's MATH unit, firstly you have to add MATH to the USES statement of your unit.

Next, supposing that P is a floating point number ("real" number), you can use the function like this:

   P := Power(3, 2);   // 9
   P := Power(2, 3);   // 8
   P := Power(4, 0.5); // 4 to the power 0.5

Related articles

Fractional exponents
Finding the antilogarithm
Financial, statistical and related functions

DelphiLand Home :: Database Tutorials :: FAQ :: Source code :: Tips