0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\math\largeint.h
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#ifndef __LARGEINT_H__
|
|
19 |
#define __LARGEINT_H__
|
|
20 |
#include <e32std.h>
|
|
21 |
|
|
22 |
#define __ASSERT(c) __ASSERT_DEBUG(c,User::Invariant())
|
|
23 |
|
|
24 |
class TLargeIntBase
|
|
25 |
{
|
|
26 |
public:
|
|
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);
|
|
35 |
public:
|
|
36 |
void Not();
|
|
37 |
void Neg();
|
|
38 |
void Abs();
|
|
39 |
void Inc();
|
|
40 |
void Dec();
|
|
41 |
TUint32 Lsl();
|
|
42 |
TUint32 Lsr();
|
|
43 |
TUint32 Asr();
|
|
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;}
|
|
56 |
public:
|
|
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];}
|
|
81 |
public:
|
|
82 |
TInt iC;
|
|
83 |
TUint32 iX[1];
|
|
84 |
};
|
|
85 |
|
|
86 |
template <TInt n>
|
|
87 |
class TLargeInt : public TLargeIntBase
|
|
88 |
{
|
|
89 |
public:
|
|
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;}
|
|
101 |
public:
|
|
102 |
TUint32 iExtra[n-1];
|
|
103 |
};
|
|
104 |
|
|
105 |
#define CHECK(X) void __compile_assert(int __check[(X)?1:-1])
|
|
106 |
|
|
107 |
#endif
|