xref: /PHP-8.0/ext/gmp/tests/gmp_gcdext.phpt (revision 25198277)
1--TEST--
2gmp_gcdext() basic tests
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip";
5?>
6--FILE--
7<?php
8
9$n = gmp_init("34293864345");
10$n1 = gmp_init("23434293864345");
11
12$a = array(
13    array(123,45),
14    array(4341,9734),
15    array(23487,333),
16    array(-234234,-123123),
17    array(-100,-2234),
18    array(345,"34587345"),
19    array(345,"0"),
20    array("345556456",345873),
21    array("34545345556456","323432445873"),
22    array($n, $n1),
23    );
24
25foreach ($a as $val) {
26    $r = gmp_gcdext($val[0],$val[1]);
27    $check = gmp_add(gmp_mul($val[0],$r['s']), gmp_mul($val[1],$r['t']));
28    var_dump(gmp_strval($r['g']));
29    var_dump(gmp_strval($check));
30}
31
32try {
33    var_dump(gmp_gcdext($val[0], array()));
34} catch (\TypeError $e) {
35    echo $e->getMessage() . \PHP_EOL;
36}
37try {
38    var_dump(gmp_gcdext(array(), array()));
39} catch (\TypeError $e) {
40    echo $e->getMessage() . \PHP_EOL;
41}
42
43echo "Done\n";
44?>
45--EXPECT--
46string(1) "3"
47string(1) "3"
48string(1) "1"
49string(1) "1"
50string(1) "3"
51string(1) "3"
52string(4) "3003"
53string(4) "3003"
54string(1) "2"
55string(1) "2"
56string(2) "15"
57string(2) "15"
58string(3) "345"
59string(3) "345"
60string(1) "1"
61string(1) "1"
62string(1) "1"
63string(1) "1"
64string(3) "195"
65string(3) "195"
66gmp_gcdext(): Argument #2 ($num2) must be of type GMP|string|int, array given
67gmp_gcdext(): Argument #1 ($num1) must be of type GMP|string|int, array given
68Done
69