PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/cln-1.3.2/src/integer/division/cl_I_mod.cc

#
C++ | 33 lines | 15 code | 8 blank | 10 comment | 5 complexity | c9de4557dcc3e81320c3c07ad3fc4f27 MD5 | raw file
Possible License(s): GPL-2.0
 1// mod().
 2
 3// General includes.
 4#include "base/cl_sysdep.h"
 5
 6// Specification.
 7#include "cln/integer.h"
 8
 9
10// Implementation.
11
12#include "integer/cl_I.h"
13
14namespace cln {
15
16const cl_I mod (const cl_I& x, const cl_I& y)
17{
18// Methode:
19// (mod x y) :==
20// (DIVIDE (abs x) (abs y)) -> q,r
21// Falls x,y verschiedene Vorzeichen haben und r<>0, setze r:=r-abs(y).
22// Falls x<0, setze r:=-r.
23// Liefere r.
24  var cl_I abs_y = abs(y);
25  var cl_I r = cl_divide(abs(x),abs_y).remainder;
26  if (minusp(x) != minusp(y))
27    { if (zerop(r)) { return 0; }
28      r = r - abs_y;
29    }
30  if (minusp(x)) { return -r; } else { return r; }
31}
32
33}  // namespace cln