• 04-11-2010, 20:33:03
    #10
    AKoyun adlı üyeden alıntı: mesajı görüntüle
    http://tr.php.net/manual/tr/function.bcmul.php
    <?php
     echo bcmul('2342342342342342342342','234234234234234234234')
    ?>
    konuyu tam okumadınız heralde =)
    bc kütüphanesinin çarpma kapasitesi sınırlıdır, onun bir üst versiyonu olan kendi fonksiyonumda da kullandıgım gmp kütüphanesidir, fakat onun da kapasitesi sınırlıdır.
    http://tr.php.net/gmp

    milyon basamaklardan bahsediyorum
  • 04-11-2010, 20:35:06
    #11
    fatal adlı üyeden alıntı: mesajı görüntüle
    konuyu tam okumadınız heralde =)
    o verdiginiz fonksiyonun çarpma kapasitesi sınırlıdır, onun bir üst versiyonu olan kendi fonksiyonumda da kullandıgım gmp kütüphanesidir, fakat onun da kapasitesi sınırlıdır.

    milyon basamaklardan bahsediyorum
    sizde onun verdiği sayfayı okumamışsınız



    <?php
    
    function Mul($Num1='0',$Num2='0') {
      // check if they're both plain numbers
      if(!preg_match("/^\d+$/",$Num1)||!preg_match("/^\d+$/",$Num2)) return(0);
    
      // remove zeroes from beginning of numbers
      for($i=0;$i<strlen($Num1);$i++) if(@$Num1{$i}!='0') {$Num1=substr($Num1,$i);break;}
      for($i=0;$i<strlen($Num2);$i++) if(@$Num2{$i}!='0') {$Num2=substr($Num2,$i);break;}
    
      // get both number lengths
      $Len1=strlen($Num1);
      $Len2=strlen($Num2);
    
      // $Rema is for storing the calculated numbers and $Rema2 is for carrying the remainders
      $Rema=$Rema2=array();
    
      // we start by making a $Len1 by $Len2 table (array)
      for($y=$i=0;$y<$Len1;$y++)
        for($x=0;$x<$Len2;$x++)
          // we use the classic lattice method for calculating the multiplication..
          // this will multiply each number in $Num1 with each number in $Num2 and store it accordingly
          @$Rema[$i++%$Len2].=sprintf('%02d',(int)$Num1{$y}*(int)$Num2{$x});
    
      // cycle through each stored number
      for($y=0;$y<$Len2;$y++)
        for($x=0;$x<$Len1*2;$x++)
          // add up the numbers in the diagonal fashion the lattice method uses
          @$Rema2[Floor(($x-1)/2)+1+$y]+=(int)$Rema[$y]{$x};
    
      // reverse the results around
      $Rema2=array_reverse($Rema2);
    
      // cycle through all the results again
      for($i=0;$i<count($Rema2);$i++) {
        // reverse this item, split, keep the first digit, spread the other digits down the array
        $Rema3=str_split(strrev($Rema2[$i]));
        for($o=0;$o<count($Rema3);$o++)
          if($o==0) @$Rema2[$i+$o]=$Rema3[$o];
          else @$Rema2[$i+$o]+=$Rema3[$o];
      }
      // implode $Rema2 so it's a string and reverse it, this is the result!
      $Rema2=strrev(implode($Rema2));
    
      // just to make sure, we delete the zeros from the beginning of the result and return
      while(strlen($Rema2)>1&&$Rema2{0}=='0') $Rema2=substr($Rema2,1);
    
      return($Rema2);
    }
    
    $A='5650175242508133742';
    $B='2361030539975818701734615584174625';
    
    printf("  Mul(%s,%s); // %s\r\n",$A,$B,  Mul($A,$B));
    printf("BCMul(%s,%s); // %s\r\n",$A,$B,BCMul($A,$B)); // build-in function
    
    /*
      This will print something similar to this..
        Mul(5650175242508133742,2361030539975818701734615584174625);
      BCMul(5650175242508133742,2361030539975818701734615584174625);
    
      both of which should be followed by the answer:
      13340236303776981390475700774516825287352418182696750
    */
    
    ?>
  • 04-11-2010, 20:41:28
    #12
    Tontonq adlı üyeden alıntı: mesajı görüntüle
    sizde onun verdiği sayfayı okumamışsınız



    <?php
    
    function Mul($Num1='0',$Num2='0') {
      // check if they're both plain numbers
      if(!preg_match("/^\d+$/",$Num1)||!preg_match("/^\d+$/",$Num2)) return(0);
    
      // remove zeroes from beginning of numbers
      for($i=0;$i<strlen($Num1);$i++) if(@$Num1{$i}!='0') {$Num1=substr($Num1,$i);break;}
      for($i=0;$i<strlen($Num2);$i++) if(@$Num2{$i}!='0') {$Num2=substr($Num2,$i);break;}
    
      // get both number lengths
      $Len1=strlen($Num1);
      $Len2=strlen($Num2);
    
      // $Rema is for storing the calculated numbers and $Rema2 is for carrying the remainders
      $Rema=$Rema2=array();
    
      // we start by making a $Len1 by $Len2 table (array)
      for($y=$i=0;$y<$Len1;$y++)
        for($x=0;$x<$Len2;$x++)
          // we use the classic lattice method for calculating the multiplication..
          // this will multiply each number in $Num1 with each number in $Num2 and store it accordingly
          @$Rema[$i++%$Len2].=sprintf('%02d',(int)$Num1{$y}*(int)$Num2{$x});
    
      // cycle through each stored number
      for($y=0;$y<$Len2;$y++)
        for($x=0;$x<$Len1*2;$x++)
          // add up the numbers in the diagonal fashion the lattice method uses
          @$Rema2[Floor(($x-1)/2)+1+$y]+=(int)$Rema[$y]{$x};
    
      // reverse the results around
      $Rema2=array_reverse($Rema2);
    
      // cycle through all the results again
      for($i=0;$i<count($Rema2);$i++) {
        // reverse this item, split, keep the first digit, spread the other digits down the array
        $Rema3=str_split(strrev($Rema2[$i]));
        for($o=0;$o<count($Rema3);$o++)
          if($o==0) @$Rema2[$i+$o]=$Rema3[$o];
          else @$Rema2[$i+$o]+=$Rema3[$o];
      }
      // implode $Rema2 so it's a string and reverse it, this is the result!
      $Rema2=strrev(implode($Rema2));
    
      // just to make sure, we delete the zeros from the beginning of the result and return
      while(strlen($Rema2)>1&&$Rema2{0}=='0') $Rema2=substr($Rema2,1);
    
      return($Rema2);
    }
    
    $A='5650175242508133742';
    $B='2361030539975818701734615584174625';
    
    printf("  Mul(%s,%s); // %s\r\n",$A,$B,  Mul($A,$B));
    printf("BCMul(%s,%s); // %s\r\n",$A,$B,BCMul($A,$B)); // build-in function
    
    /*
      This will print something similar to this..
        Mul(5650175242508133742,2361030539975818701734615584174625);
      BCMul(5650175242508133742,2361030539975818701734615584174625);
    
      both of which should be followed by the answer:
      13340236303776981390475700774516825287352418182696750
    */
    
    ?>
    okumama gerek yok biliyorum o fonksiyonların hepsini, hepsini de çok kullandım, localde test edip görebilirsiniz dediğimi. milyonu geçtim 100 bin basamaklarda deneyebilir ve php nin çalışmayı kesecegini veya çıktı gelmeyecegini göreceksiniz.
  • 04-11-2010, 20:54:55
    #13
    $A='1000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000';
    $B='1000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000';

    printf(" Mul(%s,%s); // %s\r\n",$A,$B, Mul($A,$B));

    çok rahat 1.7 celeron pc de şu sonucu verdi

    Mul(1000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000,100000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 000000000000000000000000000000000); // 10000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 000000000000000000000000000
  • 04-11-2010, 21:17:33
    #14
    allta verdigim textde 695.032 basamaklı sayı var deneyebilirsin.

    http://ul.to/9xv0nz
  • 04-11-2010, 21:22:01
    #15
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Yahu bir kerede normal bilindik bir şey paylaş üstad. Acaba PHP ile bir hesap makinesi mi yazsak? Anca orada kullanırız böyle yüksek sayıları.
  • 04-11-2010, 23:54:05
    #16
    tontonq anlatamadım sanırım demek istediğimi
    senin çarptığın sayılar çok ufak sayılar, saysan ancak 600 basamaklı falan çıkarlar,
    ben ise 10 milyon basamaklı sayılardan bahsediyorum


    bu arada verdiğin açık kaynak mul fonksiyonunu ilk defa inceliyorum
    benim yukarda yazdığım fonksiyonla birebir olmuş
    klasik ilkokul çarpma tekniği yani yapılan olay.
  • 12-09-2012, 15:30:12
    #17
    programatik açıdan güzel ve kaliteli bir algoritma. Konudaki tartışma da verimli olmuş, ikinci bahsedilen fonksiyonu bilmiyordum gayet yetenekliymiş. Tabiki milyonlara vurunca iş değişiyor.