note 47654 added to ref.bc

From: Date: Wed, 24 Nov 2004 07:20:03 +0000
Subject: note 47654 added to ref.bc
Groups: php.notes 
Request: Send a blank email to php-notes+get-80957@lists.php.net to get a copy of this message
I hacked these taylor expansions up to make diagrams for some physics homework. I don't think you'll be wanting to do any real science with PHP... but what the hell, why not? I plan to implement either a spigot algorithm or something similar to generate pi in the near future. <? // arbitrary precision sin and cosine functions // author tom boothby // free for any use function bcfact($n) { $r = $n--; while($n>1) $r=bcmul($r,$n--); return $r; } function bcsin($a) { $or= $a; $r = bcsub($a,bcdiv(bcpow($a,3),6)); $i = 2; while(bccomp($or,$r)) { $or=$r; switch($i%2) { case 0: $r = bcadd($r,bcdiv(bcpow($a,$i*2+1),bcfact($i*2+1))); break; default: $r = bcsub($r,bcdiv(bcpow($a,$i*2+1),bcfact($i*2+1))); break; } $i++; } return $r; } function bccos($a) { $or= $a; $r = bcsub(1,bcdiv(bcpow($a,2),2)); $i = 2; while(bccomp($or,$r)) { $or=$r; switch($i%2) { case 0: $r = bcadd($r,bcdiv(bcpow($a,$i*2),bcfact($i*2))); break; default: $r = bcsub($r,bcdiv(bcpow($a,$i*2),bcfact($i*2))); break; } $i++; } return $r; } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.bc.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47654 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47654&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47654&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47654&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47654&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47654&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47654&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47654&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80957) next »