note 47949 added to function.pow

From: Date: Mon, 06 Dec 2004 22:19:18 +0000
Subject: note 47949 added to function.pow
Groups: php.notes 
Request: Send a blank email to php-notes+get-81458@lists.php.net to get a copy of this message
Just a note: the calculatepi function below can be speeded up a lot by skipping the pow function call and by simplifying the addition term: function calculatepi($terms) { $pi=0.0; $k=1.0; $j=1.0; while ($terms--!=0) { $pi+=$j/$k; $k+=2.0; $j*=-1; } return 4.0*$pi; } Try this for 1,000,000 iterations and you'll see that the execution time is only about a third of the version using pow printed below. Of course, one could also use pi() or M_PI... ---- Manual Page -- http://www.php.net/manual/en/function.pow.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47949 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47949&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47949&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47949&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47949&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47949&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47949&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47949&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81458) next »