blob: 9ecd1f50b8a9d372019143cc8edc2261114bd6af [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001#ifndef __DD_HEADER
2#define __DD_HEADER
3
4#include <stdint.h>
5
6typedef union {
7 long double ld;
8 struct {
9 double hi;
10 double lo;
Edward O'Callaghanccf48132009-08-09 18:41:02 +000011 }s;
12}DD;
Daniel Dunbarfd089992009-06-26 16:47:03 +000013
14typedef union {
15 double d;
16 uint64_t x;
17} doublebits;
18
19#define LOWORDER(xy,xHi,xLo,yHi,yLo) \
20 (((((xHi)*(yHi) - (xy)) + (xHi)*(yLo)) + (xLo)*(yHi)) + (xLo)*(yLo))
21
22static inline double __attribute__((always_inline))
23fabs(double x)
24{
25 doublebits result = { .d = x };
26 result.x &= UINT64_C(0x7fffffffffffffff);
27 return result.d;
28}
29
30static inline double __attribute__((always_inline))
31high26bits(double x)
32{
33 doublebits result = { .d = x };
34 result.x &= UINT64_C(0xfffffffff8000000);
35 return result.d;
36}
37
38static inline int __attribute__((always_inline))
39different_sign(double x, double y)
40{
41 doublebits xsignbit = { .d = x }, ysignbit = { .d = y };
42 int result = (int)(xsignbit.x >> 63) ^ (int)(ysignbit.x >> 63);
43 return result;
44}
45
Edward O'Callaghanccf48132009-08-09 18:41:02 +000046#endif /* __DD_HEADER */