22 #ifndef DCCLConstants20091211H
23 #define DCCLConstants20091211H
29 #include <boost/type_traits/is_integral.hpp>
30 #include <boost/type_traits/is_floating_point.hpp>
31 #include <boost/utility/enable_if.hpp>
33 #include <google/protobuf/message.h>
34 #include <google/protobuf/descriptor.h>
36 #include "dccl/bitset.h"
41 inline unsigned floor_bits2bytes(
unsigned bits)
45 inline unsigned ceil_bits2bytes(
unsigned bits)
47 enum { BYTE_MASK = 7 };
48 return (bits& BYTE_MASK) ?
49 floor_bits2bytes(bits) + 1 :
50 floor_bits2bytes(bits);
55 typedef google::protobuf::uint32
uint32;
57 typedef google::protobuf::int32
int32;
59 typedef google::protobuf::uint64
uint64;
61 typedef google::protobuf::int64
int64;
63 const unsigned BITS_IN_BYTE = 8;
65 inline std::ostream& operator<<(std::ostream& out,
69 << msg.GetDescriptor()->name()
70 <<
"]] " << msg.DebugString());
73 template<
typename Float>
75 {
return std::floor(d + 0.5); }
81 template<
typename Float>
82 typename boost::enable_if<boost::is_floating_point<Float>, Float>::type round(Float value,
int precision)
84 Float scaling = std::pow(10.0, precision);
85 return round(value*scaling)/scaling;
89 template<
typename Int>
90 Int abs(Int i) {
return (i < 0) ? -i : i; }
96 template<
typename Int>
97 typename boost::enable_if<boost::is_integral<Int>, Int>::type round(Int value,
int precision)
106 Int scaling = (Int)std::pow(10.0, -precision);
107 Int remainder = value % scaling;
110 if(remainder >= scaling/2)