]> www.ginac.de Git - cln.git/blob - src/float/misc/cl_float_format.cc
Fix compilation with GCC 4.4.
[cln.git] / src / float / misc / cl_float_format.cc
1 // float_format().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "cln/float.h"
8
9
10 // Implementation.
11
12 namespace cln {
13
14 float_format_t float_format (uintE n)
15 {
16 // Methode:
17 // Mindestens 1+n Dezimalstellen (inklusive Vorkommastelle)
18 // bedeutet mindestens ceiling((1+n)*ln(10)/ln(2)) Binärstellen.
19 // ln(10)/ln(2) = 3.321928095 = (binär) 11.0101001001101001111000010010111100110100...
20 //                       = (binär) 100 - 0.1010110110010110000111101101000111001011...
21 // Durch diese Berechnungsmethode wird das Ergebnis sicher >= (1+n)*ln(10)/ln(2)
22 // sein, evtl. um ein paar Bit zu groß aber nicht zu klein.
23         n = 1+n;
24         return (float_format_t)
25                ((n << 2)
26                 - (n >> 1) - (n >> 3) - (n >> 5) - (n >> 6)
27                 - (n >> 8) - (n >> 9) - (n >> 12) - (n >> 14)
28                 - (n >> 15) - (n >> 20) - (n >> 21) - (n >> 22)
29                 - (n >> 23) - (n >> 25) - (n >> 26) - (n >> 28)
30 #if (intEsize>32)
31                 - (n >> 32) - (n >> 33) - (n >> 34) - (n >> 35)
32 #endif
33                 );
34 }
35
36 }  // namespace cln