]> www.ginac.de Git - ginac.git/blobdiff - ginac/polynomial/cra_garner.cpp
Happy New Year!
[ginac.git] / ginac / polynomial / cra_garner.cpp
index b400adbe69fca8d9c278e3f370197faf112aa2e6..845b5aa18d20d9da02a725d794912dd3d45efadb 100644 (file)
@@ -1,11 +1,35 @@
+/** @file cra_garner.cpp
+ *
+ *  Garner's algorithm. */
+
+/*
+ *  GiNaC Copyright (C) 1999-2019 Johannes Gutenberg University Mainz, Germany
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "cra_garner.h"
+#include "compiler.h"
+
 #include <cln/integer.h>
 #include <cln/modinteger.h>
-#include <vector>
 #include <cstddef>
-#include "cra_garner.hpp"
+#include <vector>
+
+namespace cln {
 
-namespace cln
-{
 using std::vector;
 using std::size_t;
 
@@ -73,6 +97,8 @@ mixed_radix_2_ordinary(const vector<cl_I>& mixed_radix_coeffs,
 cl_I integer_cra(const vector<cl_I>& residues,
                 const vector<cl_I>& moduli)
 {
+       if (unlikely(moduli.size() < 2))
+               throw std::invalid_argument("integer_cra: need at least 2 moduli");
 
        vector<cl_MI> recips(moduli.size() - 1);
        compute_recips(recips, moduli);
@@ -85,4 +111,3 @@ cl_I integer_cra(const vector<cl_I>& residues,
 }
 
 } // namespace cln
-