]> www.ginac.de Git - cln.git/blobdiff - src/numtheory/cl_nt_sqrtmodp.cc
Recommendation for g++-3.1 users.
[cln.git] / src / numtheory / cl_nt_sqrtmodp.cc
index 30cc80132e6cf682c7c03c1737e2363d3f0d6d74..098c4065e0803c1146fe63d473dd43f4b6076ffe 100644 (file)
@@ -4,18 +4,20 @@
 #include "cl_sysdep.h"
 
 // Specification.
-#include "cl_numtheory.h"
+#include "cln/numtheory.h"
 
 
 // Implementation.
 
 #include "cl_I.h"
-#include "cl_abort.h"
+#include "cln/abort.h"
 
 #undef floor
-#include <math.h>
+#include <cmath>
 #define floor cln_floor
 
+namespace cln {
+
 // Algorithm 1 (for very small p only):
 // Try different values.
 // Assume p is prime and a nonzero square in Z/pZ.
@@ -73,7 +75,7 @@ static const sqrt_mod_p_t cantor_zassenhaus_sqrt (const cl_modint_ring& R, const
                }
                const pol2 square (const pol2& u)
                {
-                       return pol2(::square(u.c0) + ::square(u.c1)*a, (u.c0*u.c1)<<1);
+                       return pol2(cln::square(u.c0) + cln::square(u.c1)*a, (u.c0*u.c1)<<1);
                }
                const pol2 expt_pos (const pol2& x, const cl_I& y)
                {
@@ -119,7 +121,7 @@ static const sqrt_mod_p_t cantor_zassenhaus_sqrt (const cl_modint_ring& R, const
                        if (c1inv.condition)
                                return c1inv.condition;
                        var cl_MI z = -u.c0*c1inv;
-                       if (::square(z) == a)
+                       if (cln::square(z) == a)
                                return gcd_result(1,z);
                        else
                                return gcd_result(0);
@@ -171,6 +173,16 @@ static const sqrt_mod_p_t cantor_zassenhaus_sqrt (const cl_modint_ring& R, const
        }
 }
 
+#if defined(__GNUC__) && defined(__s390__) && (__GNUC__ == 2)  // Workaround GCC-bug (see below)
+               struct cl_sylow2gen_property : public cl_property {
+                       SUBCLASS_cl_property();
+               public:
+                       cl_I h_rep;
+                       // Constructor.
+                       cl_sylow2gen_property (const cl_symbol& k, const cl_MI& h) : cl_property (k), h_rep (h.rep) {}
+               };
+#endif
+
 // Algorithm 3 (for p > 2 only):
 // Tonelli-Shanks.
 // [Cohen, A Course in Computational Algebraic Number Theory,
@@ -211,6 +223,7 @@ static const sqrt_mod_p_t tonelli_shanks_sqrt (const cl_modint_ring& R, const cl
                // Since this computation is a bit costly, we cache its result
                // on the ring's property list.
                static const cl_symbol key = (cl_symbol)(cl_string)"generator of 2-Sylow subgroup of (Z/pZ)^*";
+#if !(defined(__GNUC__) && defined(__s390__) && (__GNUC__ == 2))  // Workaround GCC-bug (see above)
                struct cl_sylow2gen_property : public cl_property {
                        SUBCLASS_cl_property();
                public:
@@ -218,6 +231,7 @@ static const sqrt_mod_p_t tonelli_shanks_sqrt (const cl_modint_ring& R, const cl
                        // Constructor.
                        cl_sylow2gen_property (const cl_symbol& k, const cl_MI& h) : cl_property (k), h_rep (h.rep) {}
                };
+#endif
                var cl_sylow2gen_property* prop = (cl_sylow2gen_property*) R->get_property(key);
                if (prop)
                        h = cl_MI(R,prop->h_rep);
@@ -298,10 +312,12 @@ const sqrt_mod_p_t sqrt_mod_p (const cl_modint_ring& R, const cl_MI& a)
        var uintL l = integer_length(p);
        var uintL e = ord2(p-1);
        //if (e > 30 && e > l/(log((double)l)*0.72-1))
-       if (e > 30 && e > l/(log((double)l)*0.92-2.41))
+       if (e > 30 && e > l/(::log((double)l)*0.92-2.41))
                // Algorithm 2.
                return cantor_zassenhaus_sqrt(R,a);
        else
                // Algorithm 3.
                return tonelli_shanks_sqrt(R,a);
 }
+
+}  // namespace cln