note 85119 added to function.stats-harmonic-mean

From: Date: Fri, 15 Aug 2008 14:51:18 +0000
Subject: note 85119 added to function.stats-harmonic-mean
Groups: php.notes 
Request: Send a blank email to php-notes+get-143525@lists.php.net to get a copy of this message
I wrote this to calculate harmonic averages in my shares program. Hopefully this can help someone who doesn't want to use PECL. The function accepts an unlimited number of arguments without the need to place them into an array, which is better than the way the PECL extension handles the function. <?php /** * @author Daniel Morris */ function harmonic () { $num_args = func_num_args (); for ($i = 0; $i < $num_args; $i++) { $sum += 1 / func_get_arg ($i); } return $num_args / $sum; } // Tests echo harmonic (1, 2, 3, 4, 5); echo harmonic (-1, 3, 4, 10293); echo harmonic (-1, -2, -3, -4, -5); // 2.1897810218978 // -9.6022389365052 // -2.1897810218978 ?> ---- Server IP: 92.48.74.199 Probable Submitter: 217.154.124.195 ---- Manual Page -- http://www.php.net/manual/en/function.stats-harmonic-mean.php Edit -- https://master.php.net/note/edit/85119 Del: integrated -- https://master.php.net/note/delete/85119/integrated Del: useless -- https://master.php.net/note/delete/85119/useless Del: bad code -- https://master.php.net/note/delete/85119/bad+code Del: spam -- https://master.php.net/note/delete/85119/spam Del: non-english -- https://master.php.net/note/delete/85119/non-english Del: in docs -- https://master.php.net/note/delete/85119/in+docs Del: other reasons-- https://master.php.net/note/delete/85119 Reject -- https://master.php.net/note/reject/85119 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143525) next »