Back to index

glibc  2.9
math_ldbl.h
Go to the documentation of this file.
00001 #ifndef _MATH_PRIVATE_H_
00002 #error "Never use <math_ldbl.h> directly; include <math_private.h> instead."
00003 #endif
00004 
00005 /* A union which permits us to convert between a long double and
00006    three 32 bit ints.  */
00007 
00008 #if __FLOAT_WORD_ORDER == BIG_ENDIAN
00009 
00010 typedef union
00011 {
00012   long double value;
00013   struct
00014   {
00015     unsigned int empty0:32;
00016     int sign_exponent:16;
00017     unsigned int empty1:16;
00018     u_int32_t msw;
00019     u_int32_t lsw;
00020   } parts;
00021 } ieee_long_double_shape_type;
00022 
00023 #endif
00024 
00025 #if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
00026 
00027 typedef union
00028 {
00029   long double value;
00030   struct
00031   {
00032     u_int32_t lsw;
00033     u_int32_t msw;
00034     int sign_exponent:16;
00035     unsigned int empty1:16;
00036     unsigned int empty0:32;
00037   } parts;
00038 } ieee_long_double_shape_type;
00039 
00040 #endif
00041 
00042 /* Get three 32 bit ints from a double.  */
00043 
00044 #define GET_LDOUBLE_WORDS(exp,ix0,ix1,d)                \
00045 do {                                                    \
00046   ieee_long_double_shape_type ew_u;                            \
00047   ew_u.value = (d);                                     \
00048   (exp) = ew_u.parts.sign_exponent;                            \
00049   (ix0) = ew_u.parts.msw;                               \
00050   (ix1) = ew_u.parts.lsw;                               \
00051 } while (0)
00052 
00053 /* Set a double from two 32 bit ints.  */
00054 
00055 #define SET_LDOUBLE_WORDS(d,exp,ix0,ix1)                \
00056 do {                                                    \
00057   ieee_long_double_shape_type iw_u;                            \
00058   iw_u.parts.sign_exponent = (exp);                            \
00059   iw_u.parts.msw = (ix0);                               \
00060   iw_u.parts.lsw = (ix1);                               \
00061   (d) = iw_u.value;                                     \
00062 } while (0)
00063 
00064 /* Get the more significant 32 bits of a long double mantissa.  */
00065 
00066 #define GET_LDOUBLE_MSW(v,d)                                   \
00067 do {                                                    \
00068   ieee_long_double_shape_type sh_u;                            \
00069   sh_u.value = (d);                                     \
00070   (v) = sh_u.parts.msw;                                        \
00071 } while (0)
00072 
00073 /* Set the more significant 32 bits of a long double mantissa from an int.  */
00074 
00075 #define SET_LDOUBLE_MSW(d,v)                                   \
00076 do {                                                    \
00077   ieee_long_double_shape_type sh_u;                            \
00078   sh_u.value = (d);                                     \
00079   sh_u.parts.msw = (v);                                        \
00080   (d) = sh_u.value;                                     \
00081 } while (0)
00082 
00083 /* Get int from the exponent of a long double.  */
00084 
00085 #define GET_LDOUBLE_EXP(exp,d)                                 \
00086 do {                                                    \
00087   ieee_long_double_shape_type ge_u;                            \
00088   ge_u.value = (d);                                     \
00089   (exp) = ge_u.parts.sign_exponent;                            \
00090 } while (0)
00091 
00092 /* Set exponent of a long double from an int.  */
00093 
00094 #define SET_LDOUBLE_EXP(d,exp)                                 \
00095 do {                                                    \
00096   ieee_long_double_shape_type se_u;                            \
00097   se_u.value = (d);                                     \
00098   se_u.parts.sign_exponent = (exp);                            \
00099   (d) = se_u.value;                                     \
00100 } while (0)