]> www.ginac.de Git - cln.git/blob - src/integer/elem/cl_I_uminus.cc
Avoid some "suggest explicit braces to avoid ambiguous ‘else’" warnings.
[cln.git] / src / integer / elem / cl_I_uminus.cc
1 // unary operator -
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 #include "base/digitseq/cl_DS.h"
14
15 namespace cln {
16
17 const cl_I operator- (const cl_I& x)
18 {
19         if (fixnump(x)) {
20                 #if (cl_value_len < intVsize)
21                 return V_to_I(- FN_to_V(x));
22                 #elif (cl_word_size==64)
23                 return Q_to_I(- FN_to_Q(x));
24                 #elif (intVsize==32) // && (cl_value_len == intVsize)
25                 var sint32 xhi = sign_of(FN_to_V(x));
26                 var uint32 xlo = FN_to_V(x);
27                 return L2_to_I(-xhi-(xlo!=0),-xlo);
28                 #endif
29         } else {
30           // x Bignum
31           CL_ALLOCA_STACK;
32           var uintD* MSDptr;
33           var uintC len;
34           var uintD* LSDptr;
35           BN_to_NDS_1(x, MSDptr=,len=,LSDptr=); // NDS zu x bilden, len>0
36           // vorsorglich 1 Digit mehr belegen:
37           { var sintD sign = sign_of_sintD(mspref(MSDptr,0));
38             lsprefnext(MSDptr) = sign; len++;
39           }
40           // Negierschleife:
41           neg_loop_lsp(LSDptr,len);
42           // MSDigit ist nun = 0x0000 oder = 0xFFFF
43           return DS_to_I(MSDptr,len); // DS wieder zum Integer machen
44         }
45 }
46
47 }  // namespace cln