Open In App

PHP | bcpow() Function

The bcpow() function in PHP is an inbuilt function and is used to calculate the value of an arbitrary precision base number raised to another exponent number. This function accepts two arbitrary precision numbers as strings and returns the base number raised to exponent after scaling the result to a specified precision.

Syntax:



string bcpow ( $base, $exponent, $scaleVal )

Parameters: This function accepts three parameters as shown in the above syntax and explained below:

Return Value: This function returns the $base$exponent result as string.



Examples:

Input:  $base = 2, $exponent = 3 
Output: 8
Since the parameter $scaleVal is not specified so
no digits after decimal is appeared in the 
result after evaluating result

Input:  $base = 2, $exponent = 3, $scaleVal = 2
Output: 8
Note: Instead of 8.00, output of 8 is given. 
This is an exception in bc math functions.

Below programs illustrate the bcpow() function in PHP :

Program 1:




<?php
// PHP program to illustrate bcpow() function
   
// input numbers with arbitrary precision
$base = "2";
$exponent = "3"
   
// calculates the base^exponent
// the two numbers when $scaleVal is
// not specified
$res = bcpow($base, $exponent);
  
echo $res;
   
?>

Output:

2

Program 2:




<?php
// PHP program to illustrate bcpow() function
   
// input numbers with arbitrary precision
$base = "2";
$exponent = "3";
  
// scale value
$scaleVal = 4;
  
// calculates the base^exponent
// the two numbers when $scaleVal is
// specified 
$res = bcpow($base, $exponent, $scaleVal); 
  
echo $res;
?>

Output:

2

Reference:
http://php.net/manual/en/function.bcpow.php


Article Tags :