chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / sysdeps / ieee754 / ldbl-96 / math_ldbl.h
1 #ifndef _MATH_PRIVATE_H_
2 #error "Never use <math_ldbl.h> directly; include <math_private.h> instead."
3 #endif
4
5 /* A union which permits us to convert between a long double and
6    three 32 bit ints.  */
7
8 #if __FLOAT_WORD_ORDER == BIG_ENDIAN
9
10 typedef union
11 {
12   long double value;
13   struct
14   {
15     int sign_exponent:16;
16     unsigned int empty:16;
17     u_int32_t msw;
18     u_int32_t lsw;
19   } parts;
20 } ieee_long_double_shape_type;
21
22 #endif
23
24 #if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
25
26 typedef union
27 {
28   long double value;
29   struct
30   {
31     u_int32_t lsw;
32     u_int32_t msw;
33     int sign_exponent:16;
34     unsigned int empty:16;
35   } parts;
36 } ieee_long_double_shape_type;
37
38 #endif
39
40 /* Get three 32 bit ints from a double.  */
41
42 #define GET_LDOUBLE_WORDS(exp,ix0,ix1,d)                        \
43 do {                                                            \
44   ieee_long_double_shape_type ew_u;                             \
45   ew_u.value = (d);                                             \
46   (exp) = ew_u.parts.sign_exponent;                             \
47   (ix0) = ew_u.parts.msw;                                       \
48   (ix1) = ew_u.parts.lsw;                                       \
49 } while (0)
50
51 /* Set a double from two 32 bit ints.  */
52
53 #define SET_LDOUBLE_WORDS(d,exp,ix0,ix1)                        \
54 do {                                                            \
55   ieee_long_double_shape_type iw_u;                             \
56   iw_u.parts.sign_exponent = (exp);                             \
57   iw_u.parts.msw = (ix0);                                       \
58   iw_u.parts.lsw = (ix1);                                       \
59   (d) = iw_u.value;                                             \
60 } while (0)
61
62 /* Get the more significant 32 bits of a long double mantissa.  */
63
64 #define GET_LDOUBLE_MSW(v,d)                                    \
65 do {                                                            \
66   ieee_long_double_shape_type sh_u;                             \
67   sh_u.value = (d);                                             \
68   (v) = sh_u.parts.msw;                                         \
69 } while (0)
70
71 /* Set the more significant 32 bits of a long double mantissa from an int.  */
72
73 #define SET_LDOUBLE_MSW(d,v)                                    \
74 do {                                                            \
75   ieee_long_double_shape_type sh_u;                             \
76   sh_u.value = (d);                                             \
77   sh_u.parts.msw = (v);                                         \
78   (d) = sh_u.value;                                             \
79 } while (0)
80
81 /* Get int from the exponent of a long double.  */
82
83 #define GET_LDOUBLE_EXP(exp,d)                                  \
84 do {                                                            \
85   ieee_long_double_shape_type ge_u;                             \
86   ge_u.value = (d);                                             \
87   (exp) = ge_u.parts.sign_exponent;                             \
88 } while (0)
89
90 /* Set exponent of a long double from an int.  */
91
92 #define SET_LDOUBLE_EXP(d,exp)                                  \
93 do {                                                            \
94   ieee_long_double_shape_type se_u;                             \
95   se_u.value = (d);                                             \
96   se_u.parts.sign_exponent = (exp);                             \
97   (d) = se_u.value;                                             \
98 } while (0)