Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Calculating Cube Root x^(1/3) Doesn't Work [closed]

Tags:

php

math

I understand there are fairly robust math packages for PHP, but what I'm trying to do isn't that complex. I'm looking to calculate the Cube Root of a number. Solving for x in (x^3 = 100) would normally require echo 100^(1/3). Running this code in PHP returns neither an error or a correct number.

like image 936
JustinP Avatar asked Sep 19 '25 15:09

JustinP


1 Answers

The ^ character is XOR in PHP, a bitwise operator.

To perform power-operations (exponents), you should look into the PHP-defined pow() method. To use this with your sample code, it would be:

echo pow(100, 1/3);

Starting in PHP 5.6, they introduced an exponentiation operator too, **:

echo 100 ** (1/3);
like image 152
newfurniturey Avatar answered Sep 22 '25 03:09

newfurniturey