xref: /php-src/ext/gmp/tests/gmp_invert.phpt (revision bb1ef4fe)
1--TEST--
2gmp_invert() basic tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8var_dump(gmp_strval(gmp_invert(123123,5467624)));
9var_dump(gmp_strval(gmp_invert(123123,"3333334345467624")));
10var_dump(gmp_strval(gmp_invert("12312323213123123",7624)));
11
12try {
13    var_dump(gmp_strval(gmp_invert(444,0)));
14} catch (\DivisionByZeroError $e) {
15    echo $e->getMessage() . \PHP_EOL;
16}
17
18try {
19    $zero = new GMP(0);
20    var_dump(gmp_invert(5, $zero));
21} catch (\DivisionByZeroError $e) {
22    echo $e->getMessage() . \PHP_EOL;
23}
24
25var_dump(gmp_strval(gmp_invert(0,28347)));
26var_dump(gmp_strval(gmp_invert(-12,456456)));
27var_dump(gmp_strval(gmp_invert(234234,-435345)));
28
29$n = gmp_init("349827349623423452345");
30$n1 = gmp_init("3498273496234234523451");
31
32var_dump(gmp_strval(gmp_invert($n, $n1)));
33var_dump(gmp_strval(gmp_invert($n1, $n)));
34
35try {
36    var_dump(gmp_invert(array(), 1));
37} catch (\TypeError $e) {
38    echo $e->getMessage() . \PHP_EOL;
39}
40try {
41    var_dump(gmp_invert(1, array()));
42} catch (\TypeError $e) {
43    echo $e->getMessage() . \PHP_EOL;
44}
45try {
46    var_dump(gmp_invert(array(), array()));
47} catch (\TypeError $e) {
48    echo $e->getMessage() . \PHP_EOL;
49}
50
51echo "Done\n";
52?>
53--EXPECT--
54string(7) "2293131"
55string(1) "0"
56string(4) "5827"
57Division by zero
58Division by zero
59string(1) "0"
60string(1) "0"
61string(1) "0"
62string(22) "3498273496234234523441"
63string(1) "1"
64gmp_invert(): Argument #1 ($num1) must be of type GMP|string|int, array given
65gmp_invert(): Argument #2 ($num2) must be of type GMP|string|int, array given
66gmp_invert(): Argument #1 ($num1) must be of type GMP|string|int, array given
67Done
68