Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
floattidf.c File Reference
#include <float.h>
#include "int_t.h"
Include dependency graph for floattidf.c:

Go to the source code of this file.

Functions

double ___floattidf (__int128 a)
 

Function Documentation

◆ ___floattidf()

double ___floattidf ( __int128 a)

Definition at line 26 of file floattidf.c.

27{
28 if (a == 0)
29 return 0.0;
30 const unsigned N = sizeof(ti_int) * CHAR_BIT;
31 const ti_int s = a >> (N-1);
32 a = (a ^ s) - s;
33 int sd = N - __clzti2(a); /* number of significant digits */
34 int e = sd - 1; /* exponent */
35 if (sd > DBL_MANT_DIG)
36 {
37 /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
38 * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
39 * 12345678901234567890123456
40 * 1 = msb 1 bit
41 * P = bit DBL_MANT_DIG-1 bits to the right of 1
42 * Q = bit DBL_MANT_DIG bits to the right of 1
43 * R = "or" of all bits to the right of Q
44 */
45 switch (sd)
46 {
47 case DBL_MANT_DIG + 1:
48 a <<= 1;
49 break;
50 case DBL_MANT_DIG + 2:
51 break;
52 default:
53 a = ((tu_int)a >> (sd - (DBL_MANT_DIG+2))) |
54 ((a & ((tu_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
55 };
56 /* finish: */
57 a |= (a & 4) != 0; /* Or P into R */
58 ++a; /* round - this step may add a significant bit */
59 a >>= 2; /* dump Q and R */
60 /* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
61 if (a & ((tu_int)1 << DBL_MANT_DIG))
62 {
63 a >>= 1;
64 ++e;
65 }
66 /* a is now rounded to DBL_MANT_DIG bits */
67 }
68 else
69 {
70 a <<= (DBL_MANT_DIG - sd);
71 /* a is now rounded to DBL_MANT_DIG bits */
72 }
73 double_bits fb;
74 fb.u.s.high = ((uint32_t)s & 0x80000000) | /* sign */
75 ((e + 1023) << 20) | /* exponent */
76 ((uint32_t)(a >> 32) & 0x000FFFFF); /* mantissa-high */
77 fb.u.s.low = (uint32_t)a; /* mantissa-low */
78 return fb.f;
79}
unsigned __int128 tu_int
Definition fixunstfti.c:15
__int128 __clzti2(__int128 a)
Definition int_t.h:45
__int128 ti_int
Definition int_t.h:43
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
const int N
Definition quantize.cpp:54
unsigned int uint32_t
Definition stdint.h:126
double f
Definition int_t.h:39
udwords u
Definition int_t.h:38
struct udwords::@2 s
char * s
Here is the call graph for this function:
Here is the caller graph for this function: