]> www.ginac.de Git - cln.git/blob - src/float/lfloat/elem/cl_LF_to_I.cc
c0f32baf43cf146efbf37f680cff6381cab3a844
[cln.git] / src / float / lfloat / elem / cl_LF_to_I.cc
1 // cl_LF_to_I().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_LF.h"
8
9
10 // Implementation.
11
12 #include "cln/integer.h"
13 #include "cl_I.h"
14 #include "cl_DS.h"
15
16 #undef MAYBE_INLINE
17 #define MAYBE_INLINE inline
18 #include "cl_LF_minusp.cc"
19
20 namespace cln {
21
22 const cl_I cl_LF_to_I (const cl_LF& x)
23 {
24 // Methode:
25 // Falls x=0.0, Ergebnis 0.
26 // Sonst (ASH Vorzeichen*Mantisse (e-16n)).
27       var uintL uexp = TheLfloat(x)->expo;
28       if (uexp==0) { return 0; } // x=0.0 -> Ergebnis 0
29       // Mantisse zu einem Integer machen:
30       CL_ALLOCA_STACK;
31       var uintD* MSDptr;
32       var uintD* LSDptr;
33       var uintC len = TheLfloat(x)->len;
34       var uintC len1 = len+1; // brauche 1 Digit mehr
35       num_stack_alloc(len1, MSDptr=,LSDptr=);
36       copy_loop_msp(arrayMSDptr(TheLfloat(x)->data,len),MSDptr mspop 1,len); // Mantisse kopieren
37       mspref(MSDptr,0) = 0; // und zusätzliches Nulldigit
38       // Mantisse ist die UDS MSDptr/len1/LSDptr.
39       if (minusp(x))
40         // x<0 -> Mantisse negieren:
41         { neg_loop_lsp(LSDptr,len1); }
42       // Vorzeichen*Mantisse ist die DS MSDptr/len1/LSDptr.
43       // (ASH Vorzeichen*Mantisse (- e 16n)) durchführen:
44       return ash(DS_to_I(MSDptr,len1),
45                  minus(uexp, LF_exp_mid + intDsize*(uintL)len)
46                 );
47 }
48
49 }  // namespace cln