x to the power y in Delphi

Question

How we get the power of a number in Delphi?

Answer

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"), 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
 

Find related articles

Search for:  Power math   base exponent  antilogarithm


Members of the DelphiLand Club can access the full version of our tutorials, including all fully commented source code files.

Click here to become a DelphiLand Club member.

 


FAQ :: Tutorials :: Source code :: Tips