Search code examples
phpmathoperatorscalc

Math power doesn't work correctly in formula in php


I am trying to add this formula into my PHP script:

50x^(y−10)

In this example: x = 1.1 and y = 99 which makes the formula:

50*1.1^(99-10)

This should return ~241501.0278 as result. But when I apply this in PHP, I only get 110 as output.

$vocMultiplier = 1.1;
$startSkill = 99;
$amountOfHits = 50 * $vocMultiplier ^($startSkill - 10);
echo $amountOfHits;

What am I doing wrong here?

Reference: here


Solution

  • You are mis-interpreting the ^ symbol for the pow function.

    http://php.net/manual/en/function.pow.php

    ^ is the Bitwise Exclusive Or operator.