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