PHP fpow() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

The fpow() function raises a number to a power and always returns a float.

It follows the IEEE 754 rules, so problems like 0 to a negative power give INF or NAN instead of errors or warnings.

Syntax

Call fpow() with the values you need. Start with this line.

PHP
You pass a base and an exponent to fpow() and it returns the power as a float. It is available since PHP 8.4.
CallWhat it does
fpow(2, 3)Returns 8 as a float.
fpow(9, 0.5)Returns 3, which is the square root of 9.
fpow(2, -1)Returns 0.5.

fpow() needs PHP 8.4 or newer. On older versions use pow() or the ** operator.

Library declarations
PHP
fpow(float $num, float $exponent): float

Parameters

ParameterDescription
numRequired. The base number.
exponentRequired. The power that the base is raised to.

Return Value

Return ValueDescription
floatThe value of num raised to exponent. It can be INF or NAN for special cases.

PHP Examples

Example 1 — Raise numbers to a power

Use whole numbers, fractions and negative exponents.

PHP
<?php
echo fpow(2, 3) . PHP_EOL;
echo fpow(9, 0.5) . PHP_EOL;
echo fpow(2, -1) . PHP_EOL;

How It Works

  1. fpow(2, 3) is 2 x 2 x 2, which is 8.
  2. An exponent of 0.5 means square root, so fpow(9, 0.5) is 3.
  3. A negative exponent means 1 divided by the power, so fpow(2, -1) is 0.5.
  4. All three results are floats even if they look like whole numbers.

Example 2 — INF and NAN results

See what fpow() returns when the math has no normal answer.

PHP
<?php
echo fpow(0, -1) . PHP_EOL;
echo fpow(-4, 0.5) . PHP_EOL;
echo fpow(10, 400) . PHP_EOL;

How It Works

  1. 0 to the power of -1 would be 1 divided by 0, so the result is INF.
  2. The square root of a negative number is not a real number, so fpow(-4, 0.5) is NAN.
  3. 10 to the power 400 is too big for a float, so it overflows to INF.
  4. No exception is thrown in any of these cases.

Example 3 — Compare pow() and fpow()

See the difference in return types between the two functions.

PHP
<?php
echo gettype(pow(2, 3)) . PHP_EOL;
echo gettype(fpow(2, 3)) . PHP_EOL;
echo fpow(2, 10) . PHP_EOL;

How It Works

  1. pow(2, 3) with two integers returns an integer.
  2. fpow(2, 3) always returns a float, which gettype() reports as "double".
  3. fpow(2, 10) gives 1024, the number of bytes in a kilobyte.
  4. Choose fpow() when you want predictable float results.

Frequently Asked Questions

It is a function added in PHP 8.4 that raises a number to a power and always returns a float.
pow() can return an int or a float depending on the input. fpow() always returns a float and follows IEEE 754 rules.
No. It was added in PHP 8.4, so older versions report an undefined function. Use pow() instead.
It returns INF, because 0 raised to a negative power means dividing by zero.
Use an exponent of 0.5, like fpow(16, 0.5), which returns 4. The sqrt() function is simpler for this though.

Next: hexdec()

The hexdec() function converts a hexadecimal (base 16) string into a normal decimal number.

hexdec() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful