Update contrib.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\math\largeint.h
18 #ifndef __LARGEINT_H__
19 #define __LARGEINT_H__
22 #define __ASSERT(c) __ASSERT_DEBUG(c,User::Invariant())
27 enum TMode {EZeroExtend,ESignExtend,ETruncate};
28 TLargeIntBase(TInt n);
29 TLargeIntBase(TInt n, TInt32 aSigned32);
30 TLargeIntBase(TInt n, TUint32 aUnsigned32);
31 TLargeIntBase(TInt n, const TLargeIntBase&, TMode);
32 TLargeIntBase(TInt n, const TUint32* aPtr);
33 TLargeIntBase(TInt n, const Int64& aSigned64);
34 TLargeIntBase(TInt n, const Uint64& aUnsigned64);
44 void Lsl(TInt aCount);
45 void Lsr(TInt aCount);
46 void Asr(TInt aCount);
47 void Add(const TLargeIntBase&);
48 void Sub(const TLargeIntBase&);
49 void Mul(const TLargeIntBase&);
50 void DivU(const TLargeIntBase& aDivisor, TLargeIntBase& aRem);
51 void DivS(const TLargeIntBase& aDivisor, TLargeIntBase& aRem);
52 TInt CompareU(const TLargeIntBase&) const;
53 TInt CompareS(const TLargeIntBase&) const;
54 inline TLargeIntBase& operator++() {Inc(); return *this;}
55 inline TLargeIntBase& operator--() {Dec(); return *this;}
57 inline TBool operator==(const TLargeIntBase& a) const
58 {return CompareU(a)==0;}
59 inline TBool operator!=(const TLargeIntBase& a) const
60 {return CompareU(a)!=0;}
61 inline TBool Hi(const TLargeIntBase& a) const
62 {return CompareU(a)>0;}
63 inline TBool Hs(const TLargeIntBase& a) const
64 {return CompareU(a)>=0;}
65 inline TBool Lo(const TLargeIntBase& a) const
66 {return CompareU(a)<0;}
67 inline TBool Ls(const TLargeIntBase& a) const
68 {return CompareU(a)<=0;}
69 inline TBool Gt(const TLargeIntBase& a) const
70 {return CompareS(a)>0;}
71 inline TBool Ge(const TLargeIntBase& a) const
72 {return CompareS(a)>=0;}
73 inline TBool Lt(const TLargeIntBase& a) const
74 {return CompareS(a)<0;}
75 inline TBool Le(const TLargeIntBase& a) const
76 {return CompareS(a)<=0;}
77 inline TUint32& operator[](TInt a)
78 {__ASSERT(TUint32(a)<TUint32(iC)); return iX[a];}
79 inline TUint32 operator[](TInt a) const
80 {__ASSERT(TUint32(a)<TUint32(iC)); return iX[a];}
87 class TLargeInt : public TLargeIntBase
90 inline TLargeInt() : TLargeIntBase(n) {}
91 inline TLargeInt(TInt32 aSigned32) : TLargeIntBase(n,aSigned32) {}
92 inline TLargeInt(TUint32 aUnsigned32) : TLargeIntBase(n,aUnsigned32) {}
93 inline TLargeInt(const TLargeIntBase& aSrc, TMode aMode) : TLargeIntBase(n,aSrc,aMode) {}
94 inline TLargeInt(const TUint32* aPtr) : TLargeIntBase(n, aPtr) {}
95 inline TLargeInt(const Int64& aSigned64) : TLargeIntBase(n, aSigned64) {}
96 inline TLargeInt(const Uint64& aUnsigned64) : TLargeIntBase(n, aUnsigned64) {}
97 inline TLargeInt<2*n> LongMultU(const TLargeInt<n>& a) const
98 {TLargeInt<2*n> x(*this,EZeroExtend); TLargeInt<2*n> y(a,EZeroExtend); x.Mul(y); return x;}
99 inline TLargeInt<2*n> LongMultS(const TLargeInt<n>& a) const
100 {TLargeInt<2*n> x(*this,ESignExtend); TLargeInt<2*n> y(a,ESignExtend); x.Mul(y); return x;}
105 #define CHECK(X) void __compile_assert(int __check[(X)?1:-1])