]> www.ginac.de Git - cln.git/blob - src/float/conv/cl_LF_to_DF.cc
Replace unused macro with cl_unused.
[cln.git] / src / float / conv / cl_LF_to_DF.cc
1 // cl_LF_to_DF().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "float/cl_F.h"
8
9
10 // Implementation.
11
12 #include "float/lfloat/cl_LF.h"
13 #include "float/lfloat/cl_LF_impl.h"
14 #include "float/dfloat/cl_DF.h"
15 #include "base/digitseq/cl_DS.h"
16
17 namespace cln {
18
19 const cl_DF cl_LF_to_DF (const cl_LF& x)
20 {
21         // x entpacken:
22         var cl_signean sign;
23         var sintE exp;
24         var uintD* ptr;
25         var uintC len;
26         LF_decode(x, { return cl_DF_0; }, sign=,exp=,ptr=,len=,);
27         // intDsize*len-DF_mant_len-1 Bits der Mantisse wegrunden:
28         // erste k := ceiling(DF_mant_len+2,intDsize) Digits nach manthi,mantlo holen:
29         var const int shiftcount = ceiling(DF_mant_len+2,intDsize)*intDsize-(DF_mant_len+1);
30         #if (cl_word_size==64)
31         var uint64 mant = get_max64_Dptr(DF_mant_len+2,ptr);
32         ptr = ptr mspop ceiling(DF_mant_len+2,intDsize);
33         if ( ((mant & bit(shiftcount-1)) ==0) // Bit 10 war 0 -> abrunden
34              || ( ((mant & (bit(shiftcount-1)-1)) ==0) // war 1, Bits 9..0 >0 -> aufrunden
35                   && !test_loop_msp(ptr,len-ceiling(DF_mant_len+2,intDsize)) // weitere Bits /=0 -> aufrunden
36                   // round-to-even
37                   && ((mant & bit(shiftcount)) ==0)
38            )    )
39           // abrunden
40           { mant = mant >> shiftcount; }
41           else
42           // aufrunden
43           { mant = mant >> shiftcount;
44             mant = mant+1;
45             if (mant >= bit(DF_mant_len+1))
46               // Überlauf durchs Runden
47               { mant = mant>>1; exp = exp+1; } // Mantisse rechts schieben
48           }
49         return encode_DF(sign,exp,mant);
50         #else
51         var uint32 manthi = get_max32_Dptr(DF_mant_len+2-32,ptr);
52         var uint32 mantlo = get_32_Dptr(ptr mspop ceiling(DF_mant_len+2-32,intDsize));
53         ptr = ptr mspop ceiling(DF_mant_len+2,intDsize);
54         if ( ((mantlo & bit(shiftcount-1)) ==0) // Bit 10 war 0 -> abrunden
55              || ( ((mantlo & (bit(shiftcount-1)-1)) ==0) // war 1, Bits 9..0 >0 -> aufrunden
56                   && !test_loop_msp(ptr,len-ceiling(DF_mant_len+2,intDsize)) // weitere Bits /=0 -> aufrunden
57                   // round-to-even
58                   && ((mantlo & bit(shiftcount)) ==0)
59            )    )
60           // abrunden
61           { mantlo = (manthi << (32-shiftcount)) | (mantlo >> shiftcount);
62             manthi = manthi >> shiftcount;
63           }
64           else
65           // aufrunden
66           { mantlo = (manthi << (32-shiftcount)) | (mantlo >> shiftcount);
67             manthi = manthi >> shiftcount;
68             mantlo = mantlo+1;
69             if (mantlo==0)
70               { manthi = manthi+1;
71                 if (manthi >= bit(DF_mant_len+1-32))
72                   // Überlauf durchs Runden
73                   { manthi = manthi>>1; exp = exp+1; } // Mantisse rechts schieben
74           }   }
75         return encode_DF(sign,exp,manthi,mantlo);
76         #endif
77 }
78
79 }  // namespace cln