PHP Doku:: Modulo zweier Zahlen mit beliebiger Genauigkeit - function.bcmod.html

Verlauf / Chronik / History: (8) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzMathematische ErweiterungenBCMath Arbitrary Precision MathematicsBC Math Funktionenbcmod

Ein Service von Reinhard Neidl - Webprogrammierung.

BC Math Funktionen

<<bcdiv

bcmul>>

bcmod

(PHP 4, PHP 5)

bcmodModulo zweier Zahlen mit beliebiger Genauigkeit

Beschreibung

string bcmod ( string $left_operand , string $modulus )

Liefert den Modulo des left_operand unter Verwendung von modulus.

Parameter-Liste

left_operand

Der linke Operand in Stringform.

modulus

Der Modulo-Wert in Stringform.

Rückgabewerte

Gibt den Modulo als String zurück. Ist modulus 0, wird NULL zurückgegeben.

Beispiele

Beispiel #1 bcmod()-Beispiel

<?php
echo bcmod('4''2'); // 0
echo bcmod('2''4'); // 2
?>

Siehe auch

  • bcdiv() - Division zweier Zahlen beliebiger Genauigkeit


4 BenutzerBeiträge:
- Beiträge aktualisieren...
ArleCamille (okw1003 at gmail dot com)
16.11.2009 13:47
GCD made in Euclidian algorithm:
<?php
function bcgcd($a, $b)
{
    if(
$a < $b)
    {
       
$t = $b;
       
$b = $a;
       
$a = $t;
        unset(
$t);
    }
    if(
bcmod($a, $b) == "0") return $b;
    else return
bcgcd($b, bcmod($a, $b));
}
?>
hope this helps.
mcuelenaere at gmail dot com
21.12.2007 22:00
Heres an useful IBAN generate function:

<?php
function controleer_iban($iban) {
   
$iban = str_replace(array(" ", "  ", "   ", "\t"), "", $iban);
   
$iban = strtoupper(str_replace(" ", "", $iban));
    if(
strlen($iban)>34)
        return
false;
   
$acceptabel = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9 0";
   
$acceptabel = explode(" ", $acceptabel);
    for(
$i = 0; $i<strlen($iban); $i++) {
        if(
in_array(substr($iban, $i, 1), $acceptabel) === false)
            return
false;
    }
   
$alfa = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
   
$alfa = explode(" ", $alfa);
    for(
$i = 1; $i<27; $i++) {
       
$alfa_replace[] = $i+9;
    }
   
$controlegetal = str_replace($alfa, $alfa_replace, substr($iban, 4, strlen($iban)-4).substr($iban, 0, 2)."00");
   
$controlegetal = 98 - (int)bcmod($controlegetal,97);
    if((int)
$controlegetal === (int)substr($iban, 2, 2))
        return
true;
    else
        return
false;   
}
?>
sebas at stageprikbord dot nl
27.03.2007 16:53
function bc_is_even($int_str) {
  return (int)!($int_str & 1);
}

More resource efficient version of 'bc_is_even'.
lauris at night dot lt
23.12.2003 17:04
<?php
/**
 * my_bcmod - get modulus (substitute for bcmod)
 * string my_bcmod ( string left_operand, int modulus )
 * left_operand can be really big, but be carefull with modulus :(
 * by Andrius Baranauskas and Laurynas Butkus :) Vilnius, Lithuania
 **/
function my_bcmod( $x, $y )
{
   
// how many numbers to take at once? carefull not to exceed (int)
   
$take = 5;    
   
$mod = '';

    do
    {
       
$a = (int)$mod.substr( $x, 0, $take );
       
$x = substr( $x, $take );
       
$mod = $a % $y;   
    }
    while (
strlen($x) );

    return (int)
$mod;
}

// example
echo my_bcmod( "7044060001970316212900", 150 );
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)