]> www.ginac.de Git - cln.git/blob - src/integer/division/cl_I_trunc2.cc
f9d67006129e479eae9e5ecb10ef509ab21c936b
[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 "cl_integer.h"
8
9
10 // Implementation.
11
12 #include "cl_I.h"
13
14 const cl_I_div_t truncate2 (const cl_I& x, const cl_I& y)
15 {
16 // Methode:
17 // (truncate x y) :==
18 // (DIVIDE (abs x) (abs y)) -> q,r
19 // Falls x<0, setze r:=-r.
20 // Falls x,y verschiedene Vorzeichen haben, setze q:=-q.
21 // Liefere q,r.
22   var cl_I_div_t q_r = cl_divide(abs(x),abs(y));
23   var cl_I& q = q_r.quotient;
24   var cl_I& r = q_r.remainder;
25   if (minusp(x))
26     { r = -r; }
27   if (minusp(x) != minusp(y))
28     { q = -q; }
29   return q_r;
30 }