tony2001 Tue Jul 18 14:54:32 2006 UTC
Added files: (Branch: PHP_5_2)
/php-src/ext/gmp/tests gmp_nextprime.phpt
Modified files:
/php-src/ext/gmp gmp.c php_gmp.h
Log:
MFH: add gmp_nextprime()
patch by ants dot aasma at gmail dot com
http://cvs.php.net/viewvc.cgi/php-src/ext/gmp/gmp.c?r1=1.49.2.2.2.4&r2=1.49.2.2.2.5&diff_format=u
Index: php-src/ext/gmp/gmp.c
diff -u php-src/ext/gmp/gmp.c:1.49.2.2.2.4 php-src/ext/gmp/gmp.c:1.49.2.2.2.5
--- php-src/ext/gmp/gmp.c:1.49.2.2.2.4 Mon Jun 26 14:11:17 2006
+++ php-src/ext/gmp/gmp.c Tue Jul 18 14:54:32 2006
@@ -260,6 +260,11 @@
ZEND_ARG_INFO(0, start)
ZEND_END_ARG_INFO()
+static
+ZEND_BEGIN_ARG_INFO(arginfo_gmp_nextprime, 0)
+ ZEND_ARG_INFO(0, a)
+ZEND_END_ARG_INFO()
+
/* }}} */
ZEND_DECLARE_MODULE_GLOBALS(gmp)
@@ -307,6 +312,7 @@
ZEND_FE(gmp_scan1, arginfo_gmp_scan1)
ZEND_FE(gmp_popcount, arginfo_gmp_popcount)
ZEND_FE(gmp_hamdist, arginfo_gmp_hamdist)
+ ZEND_FE(gmp_nextprime, arginfo_gmp_nextprime)
{NULL, NULL, NULL} /* Must be the last line in gmp_functions[] */
};
/* }}} */
@@ -1424,6 +1430,14 @@
}
/* }}} */
+/* {{{ proto resource gmp_nextprime(resource a)
+ Finds next prime of a */
+ZEND_FUNCTION(gmp_nextprime)
+{
+ gmp_unary_op(mpz_nextprime);
+}
+/* }}} */
+
/* {{{ proto resource gmp_xor(resource a, resource b)
Calculates logical exclusive OR of a and b */
ZEND_FUNCTION(gmp_xor)
http://cvs.php.net/viewvc.cgi/php-src/ext/gmp/php_gmp.h?r1=1.12.2.1&r2=1.12.2.1.2.1&diff_format=u
Index: php-src/ext/gmp/php_gmp.h
diff -u php-src/ext/gmp/php_gmp.h:1.12.2.1
php-src/ext/gmp/php_gmp.h:1.12.2.1.2.1
--- php-src/ext/gmp/php_gmp.h:1.12.2.1 Sun Jan 1 12:50:07 2006
+++ php-src/ext/gmp/php_gmp.h Tue Jul 18 14:54:32 2006
@@ -75,6 +75,7 @@
ZEND_FUNCTION(gmp_scan1);
ZEND_FUNCTION(gmp_popcount);
ZEND_FUNCTION(gmp_hamdist);
+ZEND_FUNCTION(gmp_nextprime);
ZEND_BEGIN_MODULE_GLOBALS(gmp)
zend_bool rand_initialized;
http://cvs.php.net/viewvc.cgi/php-src/ext/gmp/tests/gmp_nextprime.phpt?view=markup&rev=1.1
Index: php-src/ext/gmp/tests/gmp_nextprime.phpt
+++ php-src/ext/gmp/tests/gmp_nextprime.phpt
--TEST--
gmp_nextprime()
--SKIPIF--
<?php if (!extension_loaded("gmp")) print "skip"; ?>
--FILE--
<?php
$n = gmp_nextprime(-1);
var_dump(gmp_strval($n));
$n = gmp_nextprime(0);
var_dump(gmp_strval($n));
$n = gmp_nextprime(-1000);
var_dump(gmp_strval($n));
$n = gmp_nextprime(1000);
var_dump(gmp_strval($n));
$n = gmp_nextprime(100000);
var_dump(gmp_strval($n));
$n = gmp_nextprime(array());
var_dump(gmp_strval($n));
$n = gmp_nextprime("");
var_dump(gmp_strval($n));
$n = gmp_nextprime(new stdclass());
var_dump(gmp_strval($n));
echo "Done\n";
?>
--EXPECTF--
string(1) "2"
string(1) "2"
string(4) "-997"
string(4) "1009"
string(6) "100003"
Warning: gmp_nextprime(): Unable to convert variable to GMP - wrong type in %s
on line %d
string(1) "0"
string(1) "0"
Warning: gmp_nextprime(): Unable to convert variable to GMP - wrong type in %s
on line %d
string(1) "0"
Done
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php