xref: /PHP-7.4/ext/gmp/tests/gmp_binomial.phpt (revision c6c9e71a)
1--TEST--
2gmp_binomial(): Binomial coefficients
3--SKIPIF--
4<?php if (!extension_loaded('gmp')) die('skip gmp extension not loaded'); ?>
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
23var_dump(gmp_binomial(5, -2));
24
25?>
26--EXPECTF--
27object(GMP)#1 (1) {
28  ["num"]=>
29  string(3) "252"
30}
31object(GMP)#1 (1) {
32  ["num"]=>
33  string(3) "252"
34}
35object(GMP)#2 (1) {
36  ["num"]=>
37  string(3) "252"
38}
39object(GMP)#2 (1) {
40  ["num"]=>
41  string(242) "65208469245472575695415972927215718683781335425416743372210247172869206520770178988927510291340552990847853030615947098118282371982392705479271195296127415562705948429404753632271959046657595132854990606768967505457396473467998111950929802400"
42}
43object(GMP)#2 (1) {
44  ["num"]=>
45  string(1) "1"
46}
47object(GMP)#2 (1) {
48  ["num"]=>
49  string(1) "0"
50}
51object(GMP)#2 (1) {
52  ["num"]=>
53  string(1) "1"
54}
55object(GMP)#2 (1) {
56  ["num"]=>
57  string(1) "1"
58}
59object(GMP)#2 (1) {
60  ["num"]=>
61  string(2) "-1"
62}
63object(GMP)#2 (1) {
64  ["num"]=>
65  string(1) "7"
66}
67
68Warning: gmp_binomial(): k cannot be negative in %s on line %d
69bool(false)
70