Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
57ae2c9
ext/gmp: Split out non-existent inverse modulo cases
Girgias Nov 2, 2024
9ee1265
ext/gmp: Use Fast ZPP for GMP functions
Girgias Nov 2, 2024
2313a46
Inline gmp_unary_opl() as it was only used once
Girgias Nov 2, 2024
290f696
ext/gmp: Create custom Fast ZPP specifier to parse into mpz_ptr
Girgias Nov 3, 2024
10003a3
ext/gmp: Use new custom ZPP specifier
Girgias Nov 2, 2024
a9e2a96
ext/gmp: Refactor generation of unary GMP functions
Girgias Nov 2, 2024
1e38760
ext/gmp: Refactor generation of some binary GMP functions
Girgias Nov 2, 2024
3964efd
ext/gmp: Use new specifier for gmp_cmp()
Girgias Nov 2, 2024
376c148
ext/gmp: Refactor gmp_random_range() to use new ZPP specifier
Girgias Nov 2, 2024
1f5ba59
ext/gmp: Refactor gmp_div_qr() to use new ZPP specifier
Girgias Nov 2, 2024
8e9b944
ext/gmp: Refactor gmp_div_(q|r)() to use new ZPP specifier
Girgias Nov 2, 2024
fabfb6f
ext/gmp: Refactor gmp_divexact() and gmp_mod() to use custom ZPP spec…
Girgias Nov 2, 2024
5199904
ext/gmp: Remove now unused FETCH_GMP_ZVAL_DEP_DEP macro
Girgias Nov 2, 2024
2681da4
ext/gmp: Refactor gmp_fact() to use new ZPP specifier
Girgias Nov 2, 2024
8b2cd8f
ext/gmp: Start refactoring operator overloading to use new parsing me…
Girgias Nov 3, 2024
2704410
ext/gmp: Convert GMP operator overloading to new parsing mechanism
Girgias Nov 3, 2024
0831608
ext/gmp: Add weak mode support for parsing
Girgias Nov 3, 2024
92ff44d
ext/gmp: Use new parsing API in shift helper
Girgias Nov 3, 2024
601f6cd
ext/gmp: Use new parsing mechanism in comparison operator overloading
Girgias Nov 3, 2024
89eaa1f
ext/gmp: Refactor gmp_cmp() test
Girgias Nov 3, 2024
0b5b947
Normalize gmp_cmp() to -1/0/+1
Girgias Nov 10, 2024
0800c68
ext/gmp: Remove redundant parenthesis
Girgias Nov 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,394 changes: 460 additions & 934 deletions ext/gmp/gmp.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ext/gmp/php_gmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ZEND_MODULE_INFO_D(gmp);
ZEND_BEGIN_MODULE_GLOBALS(gmp)
bool rand_initialized;
gmp_randstate_t rand_state;
mpz_t zpp_arg[3];
ZEND_END_MODULE_GLOBALS(gmp)

#define GMPG(v) ZEND_MODULE_GLOBALS_ACCESSOR(gmp, v)
Expand Down
4 changes: 2 additions & 2 deletions ext/gmp/tests/bug32773.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ try {
--EXPECT--
10 + 0 = 10
10 + "0" = 10
Division by zero
Division by zero
gmp_div(): Argument #2 ($num2) Division by zero
gmp_div_qr(): Argument #2 ($num2) Division by zero
38 changes: 24 additions & 14 deletions ext/gmp/tests/gmp_cmp.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@ gmp
--FILE--
<?php

var_dump(gmp_cmp(123123,-123123));
var_dump(gmp_cmp("12345678900987654321","12345678900987654321"));
var_dump(gmp_cmp("12345678900987654321","123456789009876543211"));
var_dump(gmp_cmp(0,0));
var_dump(gmp_cmp(1231222,0));
var_dump(gmp_cmp(0,345355));
function cmp_helper($l, $r) {
echo 'gmp(', var_export($l, true), ', ', var_export($r, true), '): ';
$r = gmp_cmp($l, $r);
echo match (true) {
$r === 0 => "equals\n",
$r < 0 => "right greater than left\n",
$r > 0 => "left greater than right\n",
};
}

cmp_helper(123123,-123123);
cmp_helper("12345678900987654321","12345678900987654321");
cmp_helper("12345678900987654321","123456789009876543211");
cmp_helper(0,0);
cmp_helper(1231222,0);
cmp_helper(0,345355);

$n = gmp_init("827278512385463739");
var_dump(gmp_cmp(0,$n) < 0);
$n1 = gmp_init("827278512385463739");
var_dump(gmp_cmp($n1,$n));
var_dump(gmp_cmp($n1,$n) === 0);

try {
var_dump(gmp_cmp(array(),array()));
Expand All @@ -26,13 +36,13 @@ try {
echo "Done\n";
?>
--EXPECT--
int(2)
int(0)
int(-1)
int(0)
int(1)
int(-1)
gmp(123123, -123123): left greater than right
gmp('12345678900987654321', '12345678900987654321'): equals
gmp('12345678900987654321', '123456789009876543211'): right greater than left
gmp(0, 0): equals
gmp(1231222, 0): left greater than right
gmp(0, 345355): right greater than left
bool(true)
bool(true)
int(0)
gmp_cmp(): Argument #1 ($num1) must be of type GMP|string|int, array given
Done
2 changes: 1 addition & 1 deletion ext/gmp/tests/gmp_div_q.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object(GMP)#1 (1) {
["num"]=>
string(1) "0"
}
Division by zero
gmp_div_q(): Argument #2 ($num2) Division by zero
object(GMP)#2 (1) {
["num"]=>
string(1) "0"
Expand Down
4 changes: 2 additions & 2 deletions ext/gmp/tests/gmp_div_qr.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ array(2) {
string(1) "0"
}
}
Division by zero
Division by zero
gmp_div_qr(): Argument #2 ($num2) Division by zero
gmp_div_qr(): Argument #2 ($num2) Division by zero
array(2) {
[0]=>
object(GMP)#2 (1) {
Expand Down
2 changes: 1 addition & 1 deletion ext/gmp/tests/gmp_div_r.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object(GMP)#1 (1) {
["num"]=>
string(1) "0"
}
Division by zero
gmp_div_r(): Argument #2 ($num2) Division by zero
object(GMP)#3 (1) {
["num"]=>
string(5) "12653"
Expand Down
2 changes: 1 addition & 1 deletion ext/gmp/tests/gmp_divexact.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ echo "Done\n";
?>
--EXPECT--
string(1) "0"
Division by zero
gmp_divexact(): Argument #2 ($num2) Division by zero
string(2) "10"
string(3) "512"
string(19) "5000000000000000000"
Expand Down
18 changes: 10 additions & 8 deletions ext/gmp/tests/gmp_invert.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ gmp
<?php

var_dump(gmp_strval(gmp_invert(123123,5467624)));
var_dump(gmp_strval(gmp_invert(123123,"3333334345467624")));
var_dump(gmp_strval(gmp_invert("12312323213123123",7624)));

try {
Expand All @@ -22,9 +21,11 @@ try {
echo $e->getMessage() . \PHP_EOL;
}

var_dump(gmp_strval(gmp_invert(0,28347)));
var_dump(gmp_strval(gmp_invert(-12,456456)));
var_dump(gmp_strval(gmp_invert(234234,-435345)));
echo "No inverse modulo\n";
var_dump(gmp_invert(123123,"3333334345467624"));
var_dump(gmp_invert(0,28347));
var_dump(gmp_invert(-12,456456));
var_dump(gmp_invert(234234,-435345));

$n = gmp_init("349827349623423452345");
$n1 = gmp_init("3498273496234234523451");
Expand Down Expand Up @@ -52,13 +53,14 @@ echo "Done\n";
?>
--EXPECT--
string(7) "2293131"
string(1) "0"
string(4) "5827"
Division by zero
Division by zero
string(1) "0"
string(1) "0"
string(1) "0"
No inverse modulo
bool(false)
bool(false)
bool(false)
bool(false)
string(22) "3498273496234234523441"
string(1) "1"
gmp_invert(): Argument #1 ($num1) must be of type GMP|string|int, array given
Expand Down
2 changes: 1 addition & 1 deletion ext/gmp/tests/gmp_mod.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object(GMP)#2 (1) {
["num"]=>
string(1) "0"
}
Modulo by zero
gmp_mod(): Argument #2 ($num2) Modulo by zero
gmp_mod(): Argument #1 ($num1) must be of type GMP|string|int, array given
object(GMP)#4 (1) {
["num"]=>
Expand Down
2 changes: 1 addition & 1 deletion ext/gmp/tests/gmp_strval.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ echo "Done\n";
?>
--EXPECT--
gmp_strval(): Argument #1 ($num) is not an integer string
gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
gmp_strval(): Argument #1 ($num) is not an integer string
gmp_strval(): Argument #1 ($num) must be of type GMP|string|int, resource given
string(7) "9765456"
gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36
Expand Down