CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/FWCore/Utilities/interface/math_private.h

Go to the documentation of this file.
00001 // abridged from GNU libc 2.6.1 - in detail from 
00002 //   math/math_private.h
00003 //   sysdeps/ieee754/ldbl-96/math_ldbl.h
00004 
00005 // part of ths file:
00006 /*
00007  * ====================================================
00008  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00009  *
00010  * Developed at SunPro, a Sun Microsystems, Inc. business.
00011  * Permission to use, copy, modify, and distribute this
00012  * software is freely granted, provided that this notice
00013  * is preserved.
00014  * ====================================================
00015  */
00016 
00017 #ifndef math_private_h
00018 #define math_private_h
00019 
00020 #include <sys/types.h>
00021 
00022 namespace edm {
00023   namespace math_private {
00024 
00025     // A union which permits us to convert between a float and a 32 bit int.
00026     typedef union
00027     {
00028       float value;
00029       u_int32_t word;
00030     } ieee_float_shape_type;
00031 
00032     // A union which permits us to convert between a double and two 32 bit ints.
00033     typedef union
00034     {
00035       double value;
00036       struct
00037       {
00038         u_int32_t lsw;
00039         u_int32_t msw;
00040       } parts;
00041     } ieee_double_shape_type;
00042 
00043     // A union which permits us to convert between a long double and three 32 bit ints.
00044     typedef union
00045     { 
00046       long double value;
00047       struct
00048       { 
00049         u_int32_t lsw;
00050         u_int32_t msw;
00051         int sign_exponent:16;
00052         unsigned int empty:16;
00053      // unsigned int empty1:32;   // maybe needed for 128-bit long double ? (x86-64 and/or -m128bit-long-double)
00054       } parts;
00055     } ieee_long_double_shape_type;
00056 
00057     /* Get a 32 bit int from a float.  */
00058     #define GET_FLOAT_WORD(i,d)                                     \
00059     do {                                                            \
00060       edm::math_private::ieee_float_shape_type gf_u;                \
00061       gf_u.value = (d);                                             \
00062       (i) = gf_u.word;                                              \
00063     } while (0)
00064 
00065     /* Get two 32 bit ints from a double.  */
00066     #define EXTRACT_WORDS(ix0,ix1,d)                                \
00067     do {                                                            \
00068       edm::math_private::ieee_double_shape_type ew_u;               \
00069       ew_u.value = (d);                                             \
00070       (ix0) = ew_u.parts.msw;                                       \
00071       (ix1) = ew_u.parts.lsw;                                       \
00072     } while (0)
00073 
00074     /* Get three 32 bit ints from a long double.  */
00075     #define GET_LDOUBLE_WORDS(exp,ix0,ix1,d)                        \
00076     do {                                                            \
00077         edm::math_private::ieee_long_double_shape_type ew_u;        \
00078         ew_u.value = (d);                                           \
00079         (exp) = ew_u.parts.sign_exponent;                           \
00080         (ix0) = ew_u.parts.msw;                                     \
00081         (ix1) = ew_u.parts.lsw;                                     \
00082     } while (0)
00083 
00084   } // namespace math_private
00085 } // namespace edm
00086 
00087 #endif // math_private_h