Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// +----------------------------------------------------------------------+
3
// | PHP Version 4                                                        |
4
// +----------------------------------------------------------------------+
5
// | Copyright (c) 1997-2004 The PHP Group                                |
6
// +----------------------------------------------------------------------+
7
// | This source file is subject to version 3.0 of the PHP license,       |
8
// | that is bundled with this package in the file LICENSE, and is        |
9
// | available at through the world-wide-web at                           |
10
// | http://www.php.net/license/3_0.txt.                                  |
11
// | If you did not receive a copy of the PHP license and are unable to   |
12
// | obtain it through the world-wide-web, please send a note to          |
13
// | license@php.net so we can mail you a copy immediately.               |
14
// +----------------------------------------------------------------------+
15
// | Authors: Aidan Lister <aidan@php.net>                                |
16
// +----------------------------------------------------------------------+
17
//
18
// $Id: bcinvert.php,v 1.2 2005/11/22 20:24:45 aidan Exp $
19
 
20
 
21
/**
22
 * Replace bcinvert()
23
 *
24
 * @category    PHP
25
 * @package     PHP_Compat
26
 * @link        http://php.net/function.bcinvert
27
 * @author      Sara Golemon <pollita@php.net>
28
 * @version     $Revision: 1.2 $
29
 * @since       PHP 5.2.0
30
 * @require     PHP 4.0.4 (call_user_func_array)
31
 */
32
if (!function_exists('bcinvert')) {
33
    function bcinvert($a, $n)
34
    {
35
        // Sanity check
36
        if (!is_scalar($a)) {
37
            user_error('bcinvert() expects parameter 1 to be string, ' .
38
                gettype($a) . ' given', E_USER_WARNING);
39
            return false;
40
        }
41
 
42
        if (!is_scalar($n)) {
43
            user_error('bcinvert() expects parameter 2 to be string, ' .
44
                gettype($n) . ' given', E_USER_WARNING);
45
            return false;
46
        }
47
 
48
        $u1 = $v2 = '1';
49
        $u2 = $v1 = '0';
50
        $u3 = $n;
51
        $v3 = $a;
52
 
53
        while (bccomp($v3, '0')) {
54
            $q0 = bcdiv($u3, $v3);
55
            $t1 = bcsub($u1, bcmul($q0, $v1));
56
            $t2 = bcsub($u2, bcmul($q0, $v2));
57
            $t3 = bcsub($u3, bcmul($q0, $v3));
58
 
59
            $u1 = $v1;
60
            $u2 = $v2;
61
            $u3 = $v3;
62
 
63
            $v1 = $t1;
64
            $v2 = $t2;
65
            $v3 = $t3;
66
        }
67
 
68
        if (bccomp($u2, '0') < 0) {
69
            return bcadd($u2, $n);
70
        } else {
71
            return bcmod($u2, $n);
72
        }
73
    }
74
}
75
 
76
?>