PHP: BCMath tetsz�leges pontoss�g� matematikai f�ggv�nyek - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousaspell_suggestbcaddnext
Last updated: Fri, 30 Aug 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

IV. BCMath tetsz�leges pontoss�g� matematikai f�ggv�nyek

Ha tetsz�leges pontoss�g� matematikai m�veleteket szeretn�l v�gezni, a PHP a Binary Calculator Mathematics (BCMath) f�ggv�nyeket k�n�lja erre a c�lra. Ezek a f�ggv�nyek tetsz�leges m�retben �s pontoss�ggal tudnak sz�mokat �br�zolni karaktersorozatok felhaszn�l�s�val.

El�felt�telek

Licensz k�rd�sek miatt a BCMATH k�nyvt�r a standard PHP csomagt�l k�l�n�ll� elemk�nt t�lthet� le. Egy tar-gzippelt verzi� beszerezhet� a c�men. Olvasd el a README.BCMATH f�jlt a PHP csomagodban tov�bbi inform�ci�k�rt.

Telep�t�s

PHP 4-ben ezek a f�ggv�nyek csak akkor �rhet�ek el, ha a PHP-t a --enable-bcmath be�ll�t�ssal ford�tottad. PHP 3-ban ezek a f�ggv�nyek csak akkor �rhet�ek el, ha a PHP-t NEM a --disable-bcmath be�ll�t�ssal ford�tottad.

Fut�sidej� be�ll�t�sok

Ez a kiterjeszt�s semmilyen konfigur�ci�s be�ll�t�sokat nem defini�l.

Er�forr�s t�pusok

Ez a kiterjeszt�s semmilyen er�forr�s t�pust nem defini�l.

El�redefini�lt �lland�k

Ez a kiterjeszt�s semmilyen konstans �rt�ket nem defini�l.

Tartalom
bcadd -- �sszead k�t tetsz�leges pontoss�g� sz�mot
bccomp -- �sszehasonl�t k�t tetsz�leges pontoss�g� sz�mot
bcdiv -- Eloszt k�t tetsz�leges pontoss�g� sz�mot
bcmod --  Kisz�m�tja k�t tetsz�leges pontoss�g� sz�m modulus�t
bcmul -- �sszeszoroz k�t tetsz�leges pontoss�g� sz�mot
bcpow --  Egy tetsz�leges pontoss�g� sz�mot egy m�sik hatv�ny�ra emel
bcscale --  Be�ll�tja az alap�rtelmezett sk�l�z�si �rt�ket az �sszes BCMath matematikai f�ggv�ny r�sz�re
bcsqrt --  Kisz�m�tja egy tetsz�leges pontoss�g� sz�m n�gyzetgy�k�t
bcsub --  Kivon egy tetsz�leges pontoss�g� sz�mot egy m�sikb�l
User Contributed Notes
BCMath tetsz�leges pontoss�g� matematikai f�ggv�nyek
add a note about notes
[email protected]
06-Apr-2001 10:23

The README.BCMATH currently reads:

As of PHP 4.0.4, the BC math library routines are bundled in the
standard PHP distribution. There is no need to install any additional
files.

Thanks goes to Phil Nelson, for releasing the BC math library routines
under the LGPL.

benjcarson at digitaljunkies ca
07-Jul-2002 10:17

Note that bcmath doesn't seem to handle numbers in exponential notation (i.e. "1e4"), although PHP considers such a value a number.

example:

$exp1 = "1E5";
$exp2 = "2E4";
$ans1 = bcadd($exp1, $exp2, 3);
$ans2 = $exp1 + exp2;
echo("bcadd: $exp1 + $exp2 = $ans1");
echo("php: $exp1 + $exp2 = $ans2");

// Output:
bcadd: 1E5 + 2E4 = 0.000
php: 1E5 + 2E4 = 120000

Just a gotcha if you're using passing PHP numbers into bcmath functions...

benjcarson at digitaljunkies dot ca
07-Jul-2002 11:00

In addition to my last note, here are a quick pair of functions to convert exponential notation values into bcmath-style number strings:

// exp2int converts numbers in the
// form "1.5e4" into strings
function exp2int($exp) {
list($mantissa, $exponent) = spliti("e", $exp);
list($int, $dec) = split("\.", $mantissa);
bcscale ($dec);
return bcmul($mantissa, bcpow("10", $exponent));
}

// float2exp converts floats into exponential notation
function float2exp($num) {

if (0 == $num) { return "0E1";}
list($int, $dec) = split("\.", $num);

// Extract sign
if ($int[0] == "+" || $int[0] == "-") {
$sign = substr($int, 0,1);
$int = substr($int, 1);
}

if (strlen($int) <= 1) { // abs($num) is less than 1
$i=0;
for ($i=0; $dec[$i]=='0' && $i < strlen($dec); $i++);
$exp = -$i-1;
$mantissa = substr($dec,$i,1).".".substr($dec,$i+1);
} else { // abs($num) is greater than 1
$i=0;
for ($i=0; $int[$i]=='0' && $i < strlen($int); $i++);
$exp = strlen($int)-1 - $i;
$mantissa = substr($int,$i,1).".".substr($int,$i+1).$dec;
}

return ($sign . $mantissa . "E" . $exp);
}

add a note about notes
previousaspell_suggestbcaddnext
Last updated: Fri, 30 Aug 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat Aug 31 06:19:44 2002 CEST