]> www.ginac.de Git - cln.git/blobdiff - src/numtheory/cl_nt_cornacchia4.cc
Replace unused macro with cl_unused.
[cln.git] / src / numtheory / cl_nt_cornacchia4.cc
index 460f186ffc94364e5515ab159accbfb69430c47c..0137996d9407c71c451c17b29f7b1ce626a86677 100644 (file)
@@ -1,15 +1,17 @@
 // cornacchia4().
 
 // General includes.
-#include "cl_sysdep.h"
+#include "base/cl_sysdep.h"
 
 // Specification.
-#include "cl_numtheory.h"
+#include "cln/numtheory.h"
 
 
 // Implementation.
 
-#include "cl_I.h"
+#include "integer/cl_I.h"
+
+namespace cln {
 
 // [Cohen], section 1.5.2, algorithm 1.5.3.
 // For proofs refer to [F. Morain, J.-L. Nicolas: On Cornacchia's algorithm
@@ -55,7 +57,7 @@ const cornacchia_t cornacchia4 (const cl_I& d, const cl_I& p)
                if (d==7) return cornacchia_t(1, 1,1);
                return cornacchia_t(0);
        }
-       switch (FN_to_L(logand(d,7))) {
+       switch (FN_to_V(logand(d,7))) {
                case 0: case 4: {
                        // d == 0 mod 4
                        var cornacchia_t s = cornacchia1(d>>2,p);
@@ -85,12 +87,12 @@ const cornacchia_t cornacchia4 (const cl_I& d, const cl_I& p)
                        break;
        }
        // Compute x with x^2+d == 0 mod p.
-       var cl_modint_ring R = cl_find_modint_ring(p);
+       var cl_modint_ring R = find_modint_ring(p);
        var sqrt_mod_p_t init = sqrt_mod_p(R,R->canonhom(-d));
        if (init.condition)
                return init.condition;
        if (init.solutions != 2)
-               cl_abort();
+               throw runtime_exception();
        // Compute x with x^2+d == 0 mod 4*p.
        var cl_I x0 = R->retract(init.solution[0]);
        if (evenp(x0)) { x0 = p-x0; } // Enforce x0^2+d == 0 mod 4.
@@ -113,3 +115,5 @@ const cornacchia_t cornacchia4 (const cl_I& d, const cl_I& p)
                return cornacchia_t(0);
        return cornacchia_t(1, x,y);
 }
+
+}  // namespace cln