当前位置: 首页>>代码示例>>PHP>>正文


PHP Math_BigInteger::_multiplyLower方法代码示例

本文整理汇总了PHP中Math_BigInteger::_multiplyLower方法的典型用法代码示例。如果您正苦于以下问题:PHP Math_BigInteger::_multiplyLower方法的具体用法?PHP Math_BigInteger::_multiplyLower怎么用?PHP Math_BigInteger::_multiplyLower使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Math_BigInteger的用法示例。


在下文中一共展示了Math_BigInteger::_multiplyLower方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: count

 /**
  * Performs long multiplication up to $stop digits
  *
  * If you're going to be doing array_slice($product->value, 0, $stop), some cycles can be saved.
  *
  * @see _barrett()
  * @param Math_BigInteger $x
  * @return Math_BigInteger
  * @access private
  */
 function _multiplyLower($x, $stop)
 {
     $this_length = count($this->value);
     $x_length = count($x->value);
     if (!$this_length || !$x_length) {
         // a 0 is being multiplied
         return new Math_BigInteger();
     }
     if ($this_length < $x_length) {
         return $x->_multiplyLower($this, $stop);
     }
     $product = new Math_BigInteger();
     $product->value = $this->_array_repeat(0, $this_length + $x_length);
     // the following for loop could be removed if the for loop following it
     // (the one with nested for loops) initially set $i to 0, but
     // doing so would also make the result in one set of unnecessary adds,
     // since on the outermost loops first pass, $product->value[$k] is going
     // to always be 0
     $carry = 0;
     for ($j = 0; $j < $this_length; $j++) {
         // ie. $i = 0, $k = $i
         $temp = $this->value[$j] * $x->value[0] + $carry;
         // $product->value[$k] == 0
         $carry = floor($temp / 0x4000000);
         $product->value[$j] = $temp - 0x4000000 * $carry;
     }
     if ($j < $stop) {
         $product->value[$j] = $carry;
     }
     // the above for loop is what the previous comment was talking about.  the
     // following for loop is the "one with nested for loops"
     for ($i = 1; $i < $x_length; $i++) {
         $carry = 0;
         for ($j = 0, $k = $i; $j < $this_length && $k < $stop; $j++, $k++) {
             $temp = $product->value[$k] + $this->value[$j] * $x->value[$i] + $carry;
             $carry = floor($temp / 0x4000000);
             $product->value[$k] = $temp - 0x4000000 * $carry;
         }
         if ($k < $stop) {
             $product->value[$k] = $carry;
         }
     }
     $product->is_negative = $this->is_negative != $x->is_negative;
     return $product;
 }
开发者ID:helenadeus,项目名称:s3db.map,代码行数:55,代码来源:BigInteger.php


注:本文中的Math_BigInteger::_multiplyLower方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。