Team-Fly
Previous Section Next Section

14.1 Arithmetic

The following member functions implement the fundamental arithmetic operations as well as modular operations for calculation in residue class rings over the integers as accumulator operations: The object to which a called function belongs contains the function result as implicit argument after its termination. Accumulator functions are efficient, since they operate to the greatest extent without internal auxiliary objects and thus save unnecessary assignments and calls to constructors.

For the cases in which a free assignment of the results of calculations is unavoidable, or in which the automatic overwriting of the implicit argument of the member functions with the result is not desired, the member functions were extended by means of like-named analogous friend functions together with additional friend functions. These are not discussed further here, but are recorded in Appendix B. The treatment of possible error situations in LINT functions that can arise from the use of CLINT functions will be discussed in full in Chapter 15.

Before we list the public member functions, we consider first as an example of their implementation the functions

  LINT& LINT::mexp (const LINT& e, const LINT& m );

and

  LINT& LINT::mexp (const USHORT e, const LINT& m);

for exponentiation, an operation for which C++, alas, offers no operator. The functions mexp() were constructed in such a way that the functions used are, according to the type of the operands, the C functions mexpk_l(), mexpkm_l(), umexp_l(), and umexpm_l(), optimized for this purpose (with the corresponding arithmetic friend functions we are likewise dealing with the exponentiation functions wmexp_l() and wmexpm_l() with USHORT base).

 const LINT& LINT::mexp (const LINT& e, const LINT& m)
 {
   int error;
   if (!init) panic (E_LINT_VAL, "mexp", 0, __LINE__);
   if (!e.init) panic (E_LINT_VAL, "mexp", 1, __LINE__);
   if (!m.init) panic (E_LINT_VAL, "mexp", 2, __LINE__);

   err = mexp_l (n_l, e.n_l, n_l, m.n_l);
   /* mexp_l() uses mexpk_l() or mexpkm_l() */

   switch (error)
     {
        case 0:
          status = E_LINT_OK;
          break;
        case E_CLINT_DBZ:
          panic (E_LINT_DBZ, "mexp", 2, __LINE__);
          break;
        default:
          panic (E_LINT_ERR, "mexp", error, __LINE__);
     }

   return *this;
 }
 const LINT& LINT::mexp (const USHORT e, const LINT& m)
 {
   int err;
   if (!init) panic (E_LINT_VAL, "mexp", 0, __LINE__);
   if (!m.init) panic (E_LINT_VAL, "mexp", 1, __LINE__);

   err = umexp_l (n_l, e, n_l, m.n_l);

   switch (err)
     {
        // Code as above with mexp (const LINT& e, const LINT& m)
     }
   return *this;
 }

We now present a collection of additional arithmetic and number-theoretic member functions.


Team-Fly Previous Section Next Section