xref: /PHP-8.3/ext/gmp/tests/bug52906.phpt (revision e9f783fc)
1--TEST--
2Bug #52906 gmp_mod returns negative result when non-negative is expected
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8$vals = array(
9    array(7, 3),
10    array(2, 7),
11    array(12, 7),
12    array(-2, 7),
13    array(-12, 7),
14    array(2, -7),
15    array(12, -7),
16    array(-2, -7),
17    array(-12, -7),
18);
19foreach($vals as $data) {
20    echo "{$data[0]}%{$data[1]}=".gmp_strval(gmp_mod($data[0], $data[1]));
21    echo "\n";
22    echo "{$data[0]}%{$data[1]}=".gmp_strval(gmp_mod(gmp_init($data[0]), gmp_init($data[1])));
23    echo "\n";
24}
25echo "Done\n";
26?>
27--EXPECT--
287%3=1
297%3=1
302%7=2
312%7=2
3212%7=5
3312%7=5
34-2%7=5
35-2%7=5
36-12%7=2
37-12%7=2
382%-7=2
392%-7=2
4012%-7=5
4112%-7=5
42-2%-7=5
43-2%-7=5
44-12%-7=2
45-12%-7=2
46Done
47