0

I want to compute n^(2/3) as n approaches infinity in PHP.

What I tried:

$n = "INF";
echo pow($n, (2/3));

Desired result:

INF

Actual result:

0

Any suggestions? How to compute limits in PHP?

UPDATE:

OK, first problem solved - I just needed to remove the quotation mark.
But is this actually the way to calculate a limit? Is it interpreted as a limit?

1 Answers1

1

You're passing in the string "INF" into the exponential expression, which isn't valid. Try passing in just POW:

$n = INF;
echo pow($n, (2/3));
// INF
Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
  • That actually solved the problem! Is that interpreted as a limit in PHP? – user3419936 Mar 14 '14 at 19:33
  • 2
    INF is the constant used when a number is too large for PHP. You can, though check `pow(INF, 0)` and see that it resolves to 1 correctly. In addition, `pow(INF, -1) == 0` is true – Chris Forrence Mar 14 '14 at 20:02