xref: /php-src/ext/gmp/tests/gmp_divexact.phpt (revision e9f783fc)
1--TEST--
2gmp_divexact() tests
3--EXTENSIONS--
4gmp
5--SKIPIF--
6<?php
7if (!defined('GMP_VERSION') || version_compare("4.2.1", GMP_VERSION, ">=")) {
8    die("skip your GMP is too old and will crash");
9}
10?>
11--FILE--
12<?php
13
14$r = gmp_divexact("233", "23345555555555555555555555");
15var_dump(gmp_strval($r));
16
17try {
18    $r = gmp_divexact("233", "0");
19    var_dump(gmp_strval($r));
20} catch (\DivisionByZeroError $e) {
21    echo $e->getMessage() . \PHP_EOL;
22}
23
24$r = gmp_divexact("100", "10");
25var_dump(gmp_strval($r));
26
27$r = gmp_divexact("1024", "2");
28var_dump(gmp_strval($r));
29
30$n = gmp_init("10000000000000000000");
31$r = gmp_divexact($n, "2");
32var_dump(gmp_strval($r));
33
34$r = gmp_divexact($n, "50");
35var_dump(gmp_strval($r));
36
37$n1 = gmp_init("-100000000000000000000000000");
38$r = gmp_divexact($n1, $n);
39var_dump(gmp_strval($r));
40
41echo "Done\n";
42?>
43--EXPECT--
44string(1) "0"
45Division by zero
46string(2) "10"
47string(3) "512"
48string(19) "5000000000000000000"
49string(18) "200000000000000000"
50string(9) "-10000000"
51Done
52