Stxxl  1.4.0
utils/log2.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  utils/log2.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright © 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00007  *
00008  *  Distributed under the Boost Software License, Version 1.0.
00009  *  (See accompanying file LICENSE_1_0.txt or copy at
00010  *  http://www.boost.org/LICENSE_1_0.txt)
00011  **************************************************************************/
00012 
00013 #include <iostream>
00014 #include <stxxl.h>
00015 
00016 using stxxl::LOG2;
00017 using stxxl::unsigned_type;
00018 
00019 template <unsigned_type i>
00020 void log_i()
00021 {
00022     std::cout << i << "\t" << (i < 1000000 ? "\t" : "")
00023               << stxxl::LOG2_floor<i>::value << "\t"
00024               << stxxl::LOG2<i>::floor << "\t"
00025               << stxxl::LOG2<i>::ceil << std::endl;
00026 }
00027 
00028 template <unsigned_type i>
00029 void log_ipm1()
00030 {
00031     log_i<i - 1>();
00032     log_i<i>();
00033     log_i<i + 1>();
00034     std::cout << std::endl;
00035 }
00036 
00037 int main()
00038 {
00039     std::cout << "i\t\tLOG2<i>\tLOG2<i>\tLOG2<i>" << std::endl;
00040     std::cout << "\t\t\tfloor\tceil" << std::endl;
00041     log_ipm1<1 << 0>();
00042     log_ipm1<1 << 1>();
00043     log_ipm1<1 << 2>();
00044     log_ipm1<1 << 3>();
00045     log_ipm1<1 << 4>();
00046     log_ipm1<1 << 5>();
00047     log_ipm1<1 << 6>();
00048     log_ipm1<1 << 7>();
00049     log_ipm1<1 << 8>();
00050     log_ipm1<1 << 9>();
00051     log_ipm1<1 << 10>();
00052     log_ipm1<1 << 11>();
00053     log_ipm1<1 << 12>();
00054     log_ipm1<1 << 16>();
00055     log_ipm1<1 << 24>();
00056     log_ipm1<1 << 30>();
00057     log_ipm1<1UL << 31>();
00058 #if __WORDSIZE == 64
00059     log_ipm1<1UL << 32>();
00060     log_ipm1<1UL << 33>();
00061     log_ipm1<1UL << 48>();
00062     log_ipm1<1UL << 63>();
00063 #endif
00064 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines