]> www.ginac.de Git - cln.git/blob - src/float/lfloat/elem/cl_LF_to_I.cc
a90cb28ef9f80bd12562e9d5c614a476b99598a3
[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 "cl_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 const cl_I cl_LF_to_I (const cl_LF& x)
21 {
22 // Methode:
23 // Falls x=0.0, Ergebnis 0.
24 // Sonst (ASH Vorzeichen*Mantisse (e-16n)).
25       var uintL uexp = TheLfloat(x)->expo;
26       if (uexp==0) { return 0; } // x=0.0 -> Ergebnis 0
27       // Mantisse zu einem Integer machen:
28       CL_ALLOCA_STACK;
29       var uintD* MSDptr;
30       var uintD* LSDptr;
31       var uintC len = TheLfloat(x)->len;
32       var uintC len1 = len+1; // brauche 1 Digit mehr
33       num_stack_alloc(len1, MSDptr=,LSDptr=);
34       copy_loop_msp(arrayMSDptr(TheLfloat(x)->data,len),MSDptr mspop 1,len); // Mantisse kopieren
35       mspref(MSDptr,0) = 0; // und zusätzliches Nulldigit
36       // Mantisse ist die UDS MSDptr/len1/LSDptr.
37       if (minusp(x))
38         // x<0 -> Mantisse negieren:
39         { neg_loop_lsp(LSDptr,len1); }
40       // Vorzeichen*Mantisse ist die DS MSDptr/len1/LSDptr.
41       // (ASH Vorzeichen*Mantisse (- e 16n)) durchführen:
42       return ash(DS_to_I(MSDptr,len1),
43                  minus(uexp, LF_exp_mid + intDsize*(uintL)len)
44                 );
45 }