algebramix_doc 0.3
/Users/mourrain/Devel/mmx/algebramix/include/algebramix/base_int.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : base_int.hpp
00004 * DESCRIPTION: Change of base for ints
00005 * COPYRIGHT  : (C) 2009  Joris van der Hoeven and Gregoire Lecerf
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00011 ******************************************************************************/
00012 
00013 #ifndef __MMX_BASE_INT_HPP
00014 #define __MMX_BASE_INT_HPP
00015 #include <numerix/modular_int.hpp>
00016 #include <algebramix/base.hpp>
00017 #include <algebramix/base_dicho.hpp>
00018 
00019 namespace mmx {
00020 
00021 /******************************************************************************
00022 * Variants
00023 ******************************************************************************/
00024 
00025 DEFINE_VARIANT(base_naive_int,base_signed<base_naive>)
00026 DEFINE_VARIANT(base_dicho_int,base_signed<base_dicho<base_naive> >)
00027 DEFINE_VARIANT(base_naive_uint,base_naive)
00028 DEFINE_VARIANT(base_dicho_uint,base_dicho<base_naive>)
00029 
00030 #define DECLARE_HELPER(I)                       \
00031   STMPL                                                 \
00032   struct base_naive_variant_helper<I> {                 \
00033     typedef base_naive_int BV;                          \
00034   };                                                    \
00035   STMPL                                                 \
00036   struct base_dicho_variant_helper<I> {                 \
00037     typedef base_dicho_int BV;                          \
00038   };                                                    \
00039   template<typename C>                                  \
00040   struct base_transformer_helper_unsigned<C,I> {        \
00041     typedef typename Base_transformer(C,I) Baser;       \
00042   };
00043 
00044 DECLARE_HELPER(signed char)
00045 DECLARE_HELPER(short int)
00046 DECLARE_HELPER(int)
00047 DECLARE_HELPER(long int)
00048 DECLARE_HELPER(long long int)
00049 #undef DECLARE_HELPER
00050 
00051 #define DECLARE_HELPER(I)                       \
00052   STMPL                                         \
00053   struct base_naive_variant_helper<I> { \
00054     typedef base_naive_uint BV;         \
00055   };                                            \
00056   STMPL                                         \
00057   struct base_dicho_variant_helper<I> { \
00058     typedef base_dicho_uint BV;         \
00059   };
00060 DECLARE_HELPER(unsigned char)
00061 DECLARE_HELPER(unsigned short int)
00062 DECLARE_HELPER(unsigned int)
00063 DECLARE_HELPER(unsigned long int)
00064 DECLARE_HELPER(unsigned long long int)
00065 #undef DECLARE_HELPER
00066 
00067 /******************************************************************************
00068 * Size bound
00069 ******************************************************************************/
00070 
00071 #define DECLARE_HELPER(I)                               \
00072   template<typename J>                                  \
00073   struct size_bound_in_base_helper<I,J> {               \
00074   static inline nat                                     \
00075   size (const I& s, const J& p) {                       \
00076     ASSERT (bit_size (p) > 1, "invalid base");          \
00077     return is_signed_helper<I>::value ?                 \
00078       1 + (1 + bit_size (s)) / (bit_size (p) - 1):      \
00079       1 + bit_size (s) / (bit_size (p) - 1); } };
00080 DECLARE_HELPER(signed char)
00081 DECLARE_HELPER(short int)
00082 DECLARE_HELPER(int)
00083 DECLARE_HELPER(long int)
00084 DECLARE_HELPER(long long int)
00085 DECLARE_HELPER(unsigned char)
00086 DECLARE_HELPER(unsigned short int)
00087 DECLARE_HELPER(unsigned int)
00088 DECLARE_HELPER(unsigned long int)
00089 DECLARE_HELPER(unsigned long long int)
00090 #undef DECLARE_HELPER
00091 
00092 } // namespace mmx
00093 #endif // __MMX_BASE_INT_HPP
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines