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