xref: /PHP-8.2/ext/gmp/tests/gmp_binomial.phpt (revision e9f783fc)
1--TEST--
2gmp_binomial(): Binomial coefficients
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8var_dump(gmp_binomial(10, 5));
9var_dump(gmp_binomial("10", 5));
10$n = gmp_init(10);
11var_dump(gmp_binomial($n, 5));
12
13var_dump(gmp_binomial(10000, 100));
14
15var_dump(gmp_binomial(0, 0));
16var_dump(gmp_binomial(0, 1));
17var_dump(gmp_binomial(1, 0));
18var_dump(gmp_binomial(1, 1));
19
20var_dump(gmp_binomial(-1, 5)); // == -(1 + 5 - 1 over 5)
21var_dump(gmp_binomial(-2, 6)); // == (2 + 6 - 1 over 6)
22
23try {
24    var_dump(gmp_binomial(5, -2));
25} catch (\ValueError $e) {
26    echo $e->getMessage() . \PHP_EOL;
27}
28?>
29--EXPECT--
30object(GMP)#1 (1) {
31  ["num"]=>
32  string(3) "252"
33}
34object(GMP)#1 (1) {
35  ["num"]=>
36  string(3) "252"
37}
38object(GMP)#2 (1) {
39  ["num"]=>
40  string(3) "252"
41}
42object(GMP)#2 (1) {
43  ["num"]=>
44  string(242) "65208469245472575695415972927215718683781335425416743372210247172869206520770178988927510291340552990847853030615947098118282371982392705479271195296127415562705948429404753632271959046657595132854990606768967505457396473467998111950929802400"
45}
46object(GMP)#2 (1) {
47  ["num"]=>
48  string(1) "1"
49}
50object(GMP)#2 (1) {
51  ["num"]=>
52  string(1) "0"
53}
54object(GMP)#2 (1) {
55  ["num"]=>
56  string(1) "1"
57}
58object(GMP)#2 (1) {
59  ["num"]=>
60  string(1) "1"
61}
62object(GMP)#2 (1) {
63  ["num"]=>
64  string(2) "-1"
65}
66object(GMP)#2 (1) {
67  ["num"]=>
68  string(1) "7"
69}
70gmp_binomial(): Argument #2 ($k) must be greater than or equal to 0
71