Skip to content

Commit

Permalink
- fixed bug # 19494
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/Math_BigInteger/trunk@326530 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
terrafrost committed Jul 7, 2012
1 parent ca70b62 commit f5ac56f
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions BigInteger.php
Expand Up @@ -47,26 +47,29 @@
* ?> * ?>
* </code> * </code>
* *
* LICENSE: This library is free software; you can redistribute it and/or * LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
* modify it under the terms of the GNU Lesser General Public * of this software and associated documentation files (the "Software"), to deal
* License as published by the Free Software Foundation; either * in the Software without restriction, including without limitation the rights
* version 2.1 of the License, or (at your option) any later version. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* * copies of the Software, and to permit persons to whom the Software is
* This library is distributed in the hope that it will be useful, * furnished to do so, subject to the following conditions:
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * The above copyright notice and this permission notice shall be included in
* Lesser General Public License for more details. * all copies or substantial portions of the Software.
* *
* You should have received a copy of the GNU Lesser General Public * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* License along with this library; if not, write to the Free Software * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* MA 02111-1307 USA * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* *
* @category Math * @category Math
* @package Math_BigInteger * @package Math_BigInteger
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVI Jim Wigginton * @copyright MMVI Jim Wigginton
* @license http://www.gnu.org/licenses/lgpl.txt * @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version $Id$ * @version $Id$
* @link http://pear.php.net/package/Math_BigInteger * @link http://pear.php.net/package/Math_BigInteger
*/ */
Expand Down Expand Up @@ -294,7 +297,9 @@ function Math_BigInteger($x = 0, $base = 10)
$this->value = array(); $this->value = array();
} }


if (empty($x)) { // '0' counts as empty() but when the base is 256 '0' is equal to ord('0') or 48
// '0' is the only value like this per http://php.net/empty
if (empty($x) && (abs($base) != 256 || $x !== '0')) {
return; return;
} }


Expand Down Expand Up @@ -2325,13 +2330,13 @@ function modInverse($n)
$one = new Math_BigInteger(1); $one = new Math_BigInteger(1);
} }


// $x mod $n == $x mod -$n. // $x mod -$n == $x mod $n.
$n = $n->abs(); $n = $n->abs();


if ($this->compare($zero) < 0) { if ($this->compare($zero) < 0) {
$temp = $this->abs(); $temp = $this->abs();
$temp = $temp->modInverse($n); $temp = $temp->modInverse($n);
return $negated === false ? false : $this->_normalize($n->subtract($temp)); return $this->_normalize($n->subtract($temp));
} }


extract($this->extendedGCD($n)); extract($this->extendedGCD($n));
Expand Down

0 comments on commit f5ac56f

Please sign in to comment.