]> www.ginac.de Git - cln.git/blob - src/integer/division/cl_I_trunc2.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / integer / division / cl_I_trunc2.cc
1 // truncate2().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/integer.h"
8
9
10 // Implementation.
11
12 #include "cl_I.h"
13
14 namespace cln {
15
16 const cl_I_div_t truncate2 (const cl_I& x, const cl_I& y)
17 {
18 // Methode:
19 // (truncate x y) :==
20 // (DIVIDE (abs x) (abs y)) -> q,r
21 // Falls x<0, setze r:=-r.
22 // Falls x,y verschiedene Vorzeichen haben, setze q:=-q.
23 // Liefere q,r.
24   var cl_I_div_t q_r = cl_divide(abs(x),abs(y));
25   var cl_I& q = q_r.quotient;
26   var cl_I& r = q_r.remainder;
27   if (minusp(x))
28     { r = -r; }
29   if (minusp(x) != minusp(y))
30     { q = -q; }
31   return q_r;
32 }
33
34 }  // namespace cln