]> granicus.if.org Git - php/commitdiff
MFH: add gmp_nextprime()
authorAntony Dovgal <tony2001@php.net>
Tue, 18 Jul 2006 14:54:32 +0000 (14:54 +0000)
committerAntony Dovgal <tony2001@php.net>
Tue, 18 Jul 2006 14:54:32 +0000 (14:54 +0000)
patch by ants dot aasma at gmail dot com

ext/gmp/gmp.c
ext/gmp/php_gmp.h
ext/gmp/tests/gmp_nextprime.phpt [new file with mode: 0644]

index 3e723e6f4f687dc62bb815607346bdd5d746a5be..e97977a77c2d2291801102c80b2590d0c48b2248 100644 (file)
@@ -260,6 +260,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_gmp_scan1, 0)
        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_function_entry gmp_functions[] = {
        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 @@ ZEND_FUNCTION(gmp_com)
 }
 /* }}} */
 
+/* {{{ 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)
index 7ad54723f1b353b1f7bb5d6f42dfa559c97aa90e..5af36159731bb457b6a369d2956d38d16024ba32 100644 (file)
@@ -75,6 +75,7 @@ ZEND_FUNCTION(gmp_scan0);
 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;
diff --git a/ext/gmp/tests/gmp_nextprime.phpt b/ext/gmp/tests/gmp_nextprime.phpt
new file mode 100644 (file)
index 0000000..84d945b
--- /dev/null
@@ -0,0 +1,40 @@
+--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