PageRenderTime 44ms CodeModel.GetById 14ms 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. // General includes.
  3. #include "base/cl_sysdep.h"
  4. // Specification.
  5. #include "cln/integer.h"
  6. // Implementation.
  7. #include "integer/cl_I.h"
  8. namespace cln {
  9. const cl_I mod (const cl_I& x, const cl_I& y)
  10. {
  11. // Methode:
  12. // (mod x y) :==
  13. // (DIVIDE (abs x) (abs y)) -> q,r
  14. // Falls x,y verschiedene Vorzeichen haben und r<>0, setze r:=r-abs(y).
  15. // Falls x<0, setze r:=-r.
  16. // Liefere r.
  17. var cl_I abs_y = abs(y);
  18. var cl_I r = cl_divide(abs(x),abs_y).remainder;
  19. if (minusp(x) != minusp(y))
  20. { if (zerop(r)) { return 0; }
  21. r = r - abs_y;
  22. }
  23. if (minusp(x)) { return -r; } else { return r; }
  24. }
  25. } // namespace cln