~ubuntu-branches/ubuntu/wily/musl/wily

« back to all changes in this revision

Viewing changes to src/math/fmal.c

  • Committer: Package Import Robot
  • Author(s): Kevin Bortis
  • Date: 2013-09-27 23:47:18 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130927234718-a96bgcnvzx5buf60
Tags: 0.9.14-1
* Import upstream version 0.9.14
* Only build on fully supported architectures
* Point to new homepage in control file (Closes: #724277)
* Revorked debian/rules
* Solved possible problem with postrm script (Closes: #724247)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
}
35
35
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
36
36
#include <fenv.h>
 
37
#if LDBL_MANT_DIG == 64
 
38
#define LASTBIT(u) (u.i.m & 1)
 
39
#define SPLIT (0x1p32L + 1)
 
40
#elif LDBL_MANT_DIG == 113
 
41
#define LASTBIT(u) (u.i.lo & 1)
 
42
#define SPLIT (0x1p57L + 1)
 
43
#endif
37
44
 
38
45
/*
39
46
 * A struct dd represents a floating-point number with twice the precision
75
82
static inline long double add_adjusted(long double a, long double b)
76
83
{
77
84
        struct dd sum;
78
 
        union IEEEl2bits u;
 
85
        union ldshape u;
79
86
 
80
87
        sum = dd_add(a, b);
81
88
        if (sum.lo != 0) {
82
 
                u.e = sum.hi;
83
 
                if ((u.bits.manl & 1) == 0)
 
89
                u.f = sum.hi;
 
90
                if (!LASTBIT(u))
84
91
                        sum.hi = nextafterl(sum.hi, INFINITY * sum.lo);
85
92
        }
86
93
        return (sum.hi);
95
102
{
96
103
        struct dd sum;
97
104
        int bits_lost;
98
 
        union IEEEl2bits u;
 
105
        union ldshape u;
99
106
 
100
107
        sum = dd_add(a, b);
101
108
 
110
117
         * break the ties manually.
111
118
         */
112
119
        if (sum.lo != 0) {
113
 
                u.e = sum.hi;
114
 
                bits_lost = -u.bits.exp - scale + 1;
115
 
                if (bits_lost != 1 ^ (int)(u.bits.manl & 1))
 
120
                u.f = sum.hi;
 
121
                bits_lost = -u.i.se - scale + 1;
 
122
                if ((bits_lost != 1) ^ LASTBIT(u))
116
123
                        sum.hi = nextafterl(sum.hi, INFINITY * sum.lo);
117
124
        }
118
125
        return scalbnl(sum.hi, scale);
125
132
 */
126
133
static inline struct dd dd_mul(long double a, long double b)
127
134
{
128
 
#if LDBL_MANT_DIG == 64
129
 
        static const long double split = 0x1p32L + 1.0;
130
 
#elif LDBL_MANT_DIG == 113
131
 
        static const long double split = 0x1p57L + 1.0;
132
 
#endif
133
135
        struct dd ret;
134
136
        long double ha, hb, la, lb, p, q;
135
137
 
136
 
        p = a * split;
 
138
        p = a * SPLIT;
137
139
        ha = a - p;
138
140
        ha += p;
139
141
        la = a - ha;
140
142
 
141
 
        p = b * split;
 
143
        p = b * SPLIT;
142
144
        hb = b - p;
143
145
        hb += p;
144
146
        lb = b - hb;