Jump to content

PHP math explanation


zavin

Recommended Posts

Most of my site I wrote and so I know how and why ot works. Some of the stuff on my site a gathered from other sources. I have to know what every thing does so I'm hoping someone can explain in detail exactly how the following math works. If someone could use an example to explain I would appreciate it. Thanks in advance for any help provided.

Link to comment
Share on other sites

lol I guess it would help if I included the code I am referring to. Didn't notice it was missing until shlumph's post.

function Get_The_Level($exp) {
  $a=0;
  $end =0;
  for($x=1; ($end==0 && $x<100); $x++) {
    $a += floor($x+1500*pow(4, ($x/7)));
    if ($exp >= floor($a/4)){
} else {
  return $x;
  $end=1;
}
  }

Link to comment
Share on other sites

Well, it's already fairly straightforward, so I don't know what you want someone to explain....

 

Perhaps translate it to more math-ish terms?

 

for variables a = 0, b = 0, x = 1:

 

while end is 0 and x is less than 100:

a += greatest integer value of $x+1500*4^($x/7)

if(exp < greatest integer value of a/4)

    exit the function and return x.

 

 

 

By the way, the PHP code is not optimized.

 

function Get_The_Level($exp) {
$a=0;
for($x=1; $x < 100; ++$x) {
	$a += floor($x+1500*pow(4, ($x/7)));
	if($exp < floor($a/4)){
		return $x;
	}
}
}

 

 

Link to comment
Share on other sites

Also it's entirely pointless doing anything with variables (or, indeed, anything at all) after returning from a function. The code is entirely unreachable - the program counter's already been returned to the caller and all the local variables of the function have been popped from the stack.

 

So setting $end to 1 here is never ever ever executed:

 

     return $x;
     $end=1;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.