]> www.ginac.de Git - cln.git/blobdiff - src/polynomial/elem/cl_UP_number.h
* */*: Remove cl_boolean, cl_true, and cl_false in favor of built-in
[cln.git] / src / polynomial / elem / cl_UP_number.h
index c5b5183a753d793aa000f1a8b52fea8b2f5b5f64..b6cb8a843bac1772cb32681678c177547b76665a 100644 (file)
@@ -3,7 +3,7 @@
 #include "cln/SV_number.h"
 #include "cln/number.h"
 #include "cln/integer.h"
-#include "cln/abort.h"
+#include "cln/exception.h"
 
 namespace cln {
 
@@ -56,7 +56,7 @@ static void num_fprint (cl_heap_univpoly_ring* UPR, std::ostream& stream, const
        }
 }}
 
-static cl_boolean num_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
+static bool num_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
 {{
        DeclarePoly(cl_SV_number,x);
        DeclarePoly(cl_SV_number,y);
@@ -64,11 +64,11 @@ static cl_boolean num_equal (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const
        var sintL xlen = x.length();
        var sintL ylen = y.length();
        if (!(xlen == ylen))
-               return cl_false;
+               return false;
        for (var sintL i = xlen-1; i >= 0; i--)
                if (!ops.equal(x[i],y[i]))
-                       return cl_false;
-       return cl_true;
+                       return false;
+       return true;
 }}
 
 static const _cl_UP num_zero (cl_heap_univpoly_ring* UPR)
@@ -76,15 +76,15 @@ static const _cl_UP num_zero (cl_heap_univpoly_ring* UPR)
        return _cl_UP(UPR, cl_null_SV_number);
 }
 
-static cl_boolean num_zerop (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
+static bool num_zerop (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
 {
        unused UPR;
  {     DeclarePoly(cl_SV_number,x);
        var sintL xlen = x.length();
        if (xlen == 0)
-               return cl_true;
+               return true;
        else
-               return cl_false;
+               return false;
 }}
 
 static const _cl_UP num_plus (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const _cl_UP& y)
@@ -142,7 +142,7 @@ static const _cl_UP num_uminus (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
        // Negate. No normalization necessary, since the degree doesn't change.
        var sintL i = xlen-1;
        var cl_number hicoeff = ops.uminus(x[i]);
-       if (ops.zerop(hicoeff)) cl_abort();
+       if (ops.zerop(hicoeff)) throw runtime_exception();
        var cl_SV_number result = cl_SV_number(cl_make_heap_SV_number_uninit(xlen));
        init1(cl_number, result[i]) (hicoeff);
        for (i-- ; i >= 0; i--)
@@ -251,7 +251,7 @@ static const _cl_UP num_mul (cl_heap_univpoly_ring* UPR, const _cl_UP& x, const
        }
        // Normalize (not necessary in integral domains).
        //num_normalize(ops,result,len);
-       if (ops.zerop(result[len-1])) cl_abort();
+       if (ops.zerop(result[len-1])) throw runtime_exception();
        return _cl_UP(UPR, result);
 }}
 
@@ -290,7 +290,7 @@ static const _cl_UP num_square (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
        init1(cl_number, result[0]) (ops.square(x[0]));
        // Normalize (not necessary in integral domains).
        //num_normalize(ops,result,len);
-       if (ops.zerop(result[len-1])) cl_abort();
+       if (ops.zerop(result[len-1])) throw runtime_exception();
        return _cl_UP(UPR, result);
 }}
 
@@ -310,7 +310,7 @@ static const _cl_UP num_exptpos (cl_heap_univpoly_ring* UPR, const _cl_UP& x, co
 
 static const _cl_UP num_scalmul (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, const _cl_UP& y)
 {
-       if (!(UPR->basering() == x.ring())) cl_abort();
+       if (!(UPR->basering() == x.ring())) throw runtime_exception();
  {
        DeclarePoly(cl_number,x);
        DeclarePoly(cl_SV_number,y);
@@ -349,7 +349,7 @@ static sintL num_ldegree (cl_heap_univpoly_ring* UPR, const _cl_UP& x)
 
 static const _cl_UP num_monomial (cl_heap_univpoly_ring* UPR, const cl_ring_element& x, uintL e)
 {
-       if (!(UPR->basering() == x.ring())) cl_abort();
+       if (!(UPR->basering() == x.ring())) throw runtime_exception();
  {     DeclarePoly(cl_number,x);
        var cl_number_ring_ops<cl_number>& ops = *TheNumberRing(UPR->basering())->ops;
        if (ops.zerop(x))
@@ -385,9 +385,9 @@ static const _cl_UP num_create (cl_heap_univpoly_ring* UPR, sintL deg)
 static void num_set_coeff (cl_heap_univpoly_ring* UPR, _cl_UP& x, uintL index, const cl_ring_element& y)
 {{
        DeclareMutablePoly(cl_SV_number,x);
-       if (!(UPR->basering() == y.ring())) cl_abort();
+       if (!(UPR->basering() == y.ring())) throw runtime_exception();
   {    DeclarePoly(cl_number,y);
-       if (!(index < x.length())) cl_abort();
+       if (!(index < x.length())) throw runtime_exception();
        x[index] = y;
 }}}
 
@@ -407,7 +407,7 @@ static const cl_ring_element num_eval (cl_heap_univpoly_ring* UPR, const _cl_UP&
        // If y = 0, return x[0].
        // Else compute (...(x[len-1]*y+x[len-2])*y ...)*y + x[0].
        DeclarePoly(cl_SV_number,x);
-       if (!(UPR->basering() == y.ring())) cl_abort();
+       if (!(UPR->basering() == y.ring())) throw runtime_exception();
   {    DeclarePoly(cl_number,y);
        var cl_heap_number_ring* R = TheNumberRing(UPR->basering());
        var cl_number_ring_ops<cl_number>& ops = *R->ops;
@@ -463,8 +463,26 @@ class cl_heap_num_univpoly_ring : public cl_heap_univpoly_ring {
        SUBCLASS_cl_heap_univpoly_ring()
 public:
        // Constructor.
-       cl_heap_num_univpoly_ring (const cl_ring& r)
-               : cl_heap_univpoly_ring (r, &num_setops, &num_addops, &num_mulops, &num_modulops, &num_polyops) {}
+       cl_heap_num_univpoly_ring (const cl_ring& r);
+       // Destructor.
+       ~cl_heap_num_univpoly_ring () {}
 };
 
+static void cl_heap_num_univpoly_ring_destructor (cl_heap* pointer)
+{
+       (*(cl_heap_num_univpoly_ring*)pointer).~cl_heap_num_univpoly_ring();
+}
+
+cl_class cl_class_num_univpoly_ring = {
+       cl_heap_num_univpoly_ring_destructor,
+       cl_class_flags_univpoly_ring
+};
+
+// Constructor.
+inline cl_heap_num_univpoly_ring::cl_heap_num_univpoly_ring (const cl_ring& r)
+       : cl_heap_univpoly_ring (r, &num_setops, &num_addops, &num_mulops, &num_modulops, &num_polyops)
+{
+       type = &cl_class_num_univpoly_ring;
+}
+
 }  // namespace cln