21 template<
class BigInt,
int_t NDecPlaces, base_t DecBase>
24 static const int_t NDec = NDecPlaces;
25 static const base_t Base = DecBase;
29 template<
class BI,
unsigned int N,
unsigned int I=N>
30 struct ShiftLeftRound;
32 template<
bool S,
class H1,
class H2,
class T, base_t Base,
unsigned int N,
unsigned int I>
33 struct ShiftLeftRound<
SBigInt<S,Loki::Typelist<H1,Loki::Typelist<H2,T> >,Base>,N,I>
35 static const base_t HalfBase = Base >> 1;
36 typedef typename Loki::Select<(H1::value >= HalfBase),
38 typedef typename ShiftLeftRound<SBigInt<S,TList,Base>,N,I-1>::Result Result;
41 template<
bool S,
class H1,
class H2,
class T, base_t Base,
unsigned int N>
42 struct ShiftLeftRound<
SBigInt<S,Loki::Typelist<H1,Loki::Typelist<H2,T> >,Base>,N,0>
47 template<
bool S,
class H1, base_t Base,
unsigned int N,
unsigned int I>
48 struct ShiftLeftRound<
SBigInt<S,Loki::Typelist<H1,Loki::NullType>,Base>,N,I>
50 static const base_t HalfBase = Base >> 1;
51 typedef typename Loki::Select<(H1::value >= HalfBase),
52 Loki::Typelist<
SInt<1>,Loki::NullType>,Loki::NullType>::Result TList;
53 typedef typename ShiftLeftRound<SBigInt<S,TList,Base>,N,I-1>::Result Result;
56 template<
bool S,
class H1, base_t Base,
unsigned int N>
57 struct ShiftLeftRound<
SBigInt<S,Loki::Typelist<H1,Loki::NullType>,Base>,N,0>
62 template<
bool S,
class TList, base_t Base,
unsigned int N>
63 struct ShiftLeftRound<
SBigInt<S,TList,Base>,N,0>
68 template<
bool S, base_t Base,
unsigned int N,
unsigned int I>
69 struct ShiftLeftRound<
SBigInt<S,Loki::NullType,Base>,N,I>
74 template<
bool S, base_t Base,
unsigned int N>
75 struct ShiftLeftRound<
SBigInt<S,Loki::NullType,Base>,N,0>
81 template<
class BI,
int_t ND,
int Accuracy, base_t Base>
82 struct Reduce<SDecimal<BI,ND,Base>,Accuracy,Base> {
88 typedef typename Loki::Select<(ND>Accuracy),
89 typename ShiftLeftRound<BI,ND-Accuracy>::Result,BI>::Result NewBI;
90 typedef SDecimal<NewBI,Accuracy,Base> Result;
93 template<
int_t N,
int_t ND,
int Accuracy, base_t Base>
94 struct Reduce<SDecimal<
SInt<N>,ND,Base>,Accuracy,Base> {
95 typedef SDecimal<SInt<N>,Accuracy,Base> Result;
98 template<
class BI1,
int_t ND1,
class BI2,
int_t ND2, base_t DecBase>
99 class Mult<SDecimal<BI1,ND1,DecBase>,SDecimal<BI2,ND2,DecBase> > {
100 static const int_t MaxND = (ND1 > ND2) ? ND1 : ND2;
101 typedef typename Mult<BI1,BI2>::Result Prod;
102 typedef SDecimal<Prod,ND1+ND2,DecBase> NewDec;
104 typedef typename Reduce<NewDec,MaxND,DecBase>::Result Result;
107 template<
int_t N,
class BI,
int_t ND, base_t DecBase>
108 class Mult<
SInt<N>,SDecimal<BI,ND,DecBase> > {
109 typedef typename Mult<SInt<N>,BI>::Result Prod;
111 typedef SDecimal<Prod,ND,DecBase> Result;
114 template<
int_t N,
class BI,
int_t ND, base_t DecBase>
115 class Mult<SDecimal<BI,ND,DecBase>,
SInt<N> >
116 :
public Mult<SInt<N>,SDecimal<BI,ND,DecBase> > {};
120 template<
class BI1,
class BI2,
int_t ND, base_t DecBase>
121 class Add<SDecimal<BI1,ND,DecBase>,SDecimal<BI2,ND,DecBase> > {
122 typedef typename Add<BI1,BI2>::Result Sum;
124 typedef SDecimal<Sum,ND,DecBase> Result;
127 template<
class BI,
int_t ND, base_t DecBase,
int_t N>
128 class Add<SDecimal<BI,ND,DecBase>,
SInt<N> > {
129 typedef typename CreateBigInt<SInt<N>,DecBase>::Result BI1;
130 typedef typename Loki::TL::ShiftRight<typename BI1::Num,ND,SInt<0> >::Result NList;
132 typedef typename Add<BI,NewBI>::Result Sum;
134 typedef SDecimal<Sum,ND,DecBase> Result;
139 template<
class BI1,
class BI2,
int_t ND, base_t DecBase>
140 class Sub<SDecimal<BI1,ND,DecBase>,SDecimal<BI2,ND,DecBase> > {
141 typedef typename Sub<BI1,BI2>::Result Dif;
143 typedef SDecimal<Dif,ND,DecBase> Result;
148 template<
class BI,
int_t ND, base_t DecBase>
149 struct Negate<SDecimal<BI,ND,DecBase> > {
150 typedef typename Negate<BI>::Result NewBI;
151 typedef SDecimal<NewBI,ND,DecBase> Result;
156 template<
class BI,
int_t ND, base_t DecBase>
157 struct Check<SDecimal<BI,ND,DecBase> > :
public Check<BI> {};