]> www.ginac.de Git - cln.git/blobdiff - src/numtheory/cl_nt_isprobprime.cc
Remove exception hooks in favor of real C++ exceptions:
[cln.git] / src / numtheory / cl_nt_isprobprime.cc
index 2a0d096618be3b35bd535f45b668153c7bcc7940..031fe291dee7bc799b4659ceda82e12c54aa24da 100644 (file)
@@ -4,24 +4,32 @@
 #include "cl_sysdep.h"
 
 // Specification.
-#include "cl_numtheory.h"
+#include "cln/numtheory.h"
 
 
 // Implementation.
 
 #include "cl_IF.h"
-#include "cl_abort.h"
+#include "cln/integer_io.h"
+#include "cln/exception.h"
+#include <sstream>
+
+namespace cln {
 
 cl_boolean isprobprime (const cl_I& n)
 {
-       if (!(n > 0))
-               cl_abort();
+       if (!(n > 0)) {
+               std::ostringstream buf;
+               fprint(buf, n);
+               fprint(buf, " is not a positive integer.");
+               throw runtime_exception(buf.str());
+       }
        // With a Miller-Rabin count = 50 the final error probability is
        // 4^-50 < 10^-30.
        var int count = 50;
        // Step 1: Trial division (rules out 87% of all numbers quickly).
        const uint32 trialdivide_limit = 70;
-       var uintL l = integer_length(n);
+       var uintC l = integer_length(n);
        if (l <= 32) {
                var uint32 nn = cl_I_to_UL(n);
                if (nn <= cl_small_prime_table_limit) {
@@ -53,3 +61,5 @@ cl_boolean isprobprime (const cl_I& n)
        // Step 2: Miller-Rabin test.
        return cl_miller_rabin_test(n,count,NULL);
 }
+
+}  // namespace cln