]> www.ginac.de Git - cln.git/blob - src/float/lfloat/misc/cl_LF_idecode.cc
959aa3dba3b0215484e113c3f1089f568d3ff36e
[cln.git] / src / float / lfloat / misc / cl_LF_idecode.cc
1 // integer_decode_float().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_lfloat.h"
8
9
10 // Implementation.
11
12 #include "cl_LF.h"
13 #include "cl_I.h"
14 #include "cl_DS.h"
15
16 MAYBE_INLINE
17 const cl_idecoded_float integer_decode_float (const cl_LF& x)
18 {
19         // x entpacken:
20         var uintL uexp = TheLfloat(x)->expo;
21         if (uexp == 0)
22                 { return cl_idecoded_float(0, 0, 1); }
23         var cl_signean sign = TheLfloat(x)->sign;
24         var uintC len = TheLfloat(x)->len;
25         // intDsize*len >= 53 >= 33 >= cl_value_len, also len >= bn_minlength.
26         // Baue Integer für die Mantisse.
27         // Vorne 1 Nulldigit, damit es eine NDS wird.
28         var Bignum mant = allocate_bignum(1+len);
29         mspref(arrayMSDptr(TheBignum(mant)->data,1+len),0) = 0;
30         copy_loop_msp(arrayMSDptr(TheLfloat(x)->data,len),arrayMSDptr(TheBignum(mant)->data,1+len) mspop 1,len); // NUDS kopieren
31         return cl_idecoded_float(
32                 // Mantisse
33                 mant,
34                 // e-intDsize*n = uexp-LF_exp_mid-intDsize*n als Integer
35                 minus(uexp, LF_exp_mid + intDsize*(uintL)len),
36                 (sign>=0 ? cl_I(1) : cl_I(-1)) // (-1)^s erzeugen
37                );
38 }